-
Notifications
You must be signed in to change notification settings - Fork 469
Open
Description
Description
The "Clear all" filters functionality on the Features page does not properly clear the Value filter. When clicking "Clear all", the value filter input retains its value due to race conditions between the debounced search and the filter state reset.
Steps to Reproduce
- Navigate to the Features page
- Open the Value filter dropdown
- Enter a value in the "Feature Value" input
- Click "Clear all" filters button
- Expected: The Value filter input should be cleared
- Actual: The Value filter input retains its value
Root Cause
- Unstable callback references:
handleFilterChangeandgoToPageinuseFeatureFilters.tsare not memoized, causing unnecessary re-renders - Missing reset functionality:
useDebouncedSearch.tslacks aresetSearchfunction to properly clear both the input and debounced state - Single useEffect handling both reset and sync:
TableValueFilter.tsxuses one useEffect for both resetting and syncing, causing race conditions
Proposed Solution
1. Memoize callbacks in useFeatureFilters.ts
const handleFilterChange = useCallback((updates: Partial<FilterState>) => {
setFilters((prev) => ({ ...prev, ...updates }))
setPage(1)
}, [])
const goToPage = useCallback((newPage: number) => {
setPage(newPage)
}, [])2. Add resetSearch and memoize callbacks in useDebouncedSearch.ts
- Add a
resetSearchfunction that clears bothsearchInputandsearchstate - Use
useRefto store the debounced function to avoid stale closures - Memoize
handleSearchInputandresetSearchwithuseCallback
3. Separate useEffects in TableValueFilter.tsx
- Effect 1: Handle external reset (Clear all)
- Effect 2: Sync internal search state to parent
4. Memoize handleValueFilterChange in FeaturesTableFilters.tsx
Files to Modify
frontend/web/components/pages/features/hooks/useFeatureFilters.tsfrontend/common/useDebouncedSearch.tsfrontend/web/components/tables/TableValueFilter.tsxfrontend/web/components/pages/features/components/FeaturesTableFilters.tsx
Related
This issue was identified during the FeaturesPage RTK Query migration (PR #6469).
Metadata
Metadata
Assignees
Labels
No labels