fix(TC-2443): prevent redundant autocomplete API calls on Search page navigation [Backport release/0.5.z]#1136
Conversation
Reviewer's GuideBackports the SearchMenu autocomplete gating fix to avoid redundant autocomplete API calls after navigation or filter changes by stabilizing the applied search value, tightening when autocomplete is enabled, and adding regression tests around the new behavior. Sequence diagram for SearchMenu search submission and filter syncsequenceDiagram
actor User
participant SearchMenu
participant SbomSearchContext
participant AutocompleteFetchers
User->>SearchMenu: type into input
SearchMenu->>SearchMenu: setSearchValue
SearchMenu->>SearchMenu: setIsSearchValueDirty(true)
SearchMenu->>SearchMenu: useDebounceValue(searchValue)
SearchMenu->>AutocompleteFetchers: useAllEntities(debouncedSearchValue, false)
User->>SearchMenu: click Search button
SearchMenu->>SearchMenu: setIsSearchValueDirty(false)
SearchMenu->>SearchMenu: setIsAutocompleteOpen(false)
SearchMenu->>SearchMenu: submittedSearchValueRef.current = searchValue
SearchMenu->>SbomSearchContext: onChangeSearch(searchValue)
SearchMenu->>AutocompleteFetchers: useAllEntities(debouncedSearchValue, true)
SbomSearchContext-->>SearchMenu: filterState.filterValues updated
SearchMenu->>SearchMenu: appliedSearchValue extracted
SearchMenu->>SearchMenu: useEffect([appliedSearchValue, isSearchValueDirty])
alt submittedSearchValueRef.current === appliedSearchValue
SearchMenu->>SearchMenu: submittedSearchValueRef.current = null
SearchMenu->>SearchMenu: setSearchValue(appliedSearchValue)
else isSearchValueDirty === false and no submitted value
SearchMenu->>SearchMenu: setSearchValue(appliedSearchValue)
end
User->>SearchMenu: click Reset button
SearchMenu->>SearchMenu: setSearchValue("")
SearchMenu->>SearchMenu: setIsSearchValueDirty(false)
SearchMenu->>SearchMenu: setIsAutocompleteOpen(false)
SearchMenu->>SearchMenu: submittedSearchValueRef.current = ""
SearchMenu->>SbomSearchContext: onChangeSearch("")
SearchMenu->>AutocompleteFetchers: useAllEntities("", true)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
disableAutocompleteboolean is derived as a negation ofisSearchValueDirtyand then passed through multiple layers; consider renaming it (e.g.,shouldDisableAutocomplete) or inverting the condition at the call site to improve readability of the on/off logic across the component. - The
submittedSearchValueReflifecycle (null vs empty string) is subtle and drives multiple branches in the effect; adding a small helper function or encapsulating this state machine into a custom hook would make the intent and transitions easier to reason about and maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `disableAutocomplete` boolean is derived as a negation of `isSearchValueDirty` and then passed through multiple layers; consider renaming it (e.g., `shouldDisableAutocomplete`) or inverting the condition at the call site to improve readability of the on/off logic across the component.
- The `submittedSearchValueRef` lifecycle (null vs empty string) is subtle and drives multiple branches in the effect; adding a small helper function or encapsulating this state machine into a custom hook would make the intent and transitions easier to reason about and maintain.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/0.5.z #1136 +/- ##
=================================================
+ Coverage 50.59% 51.10% +0.50%
=================================================
Files 256 256
Lines 5506 5522 +16
Branches 1667 1672 +5
=================================================
+ Hits 2786 2822 +36
+ Misses 2450 2432 -18
+ Partials 270 268 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Backport of #1116 to
release/0.5.z.Summary by Sourcery
Prevent redundant search autocomplete API calls when navigating the Search page and synchronizing with URL-based filters.
Bug Fixes:
Tests: