-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix deploy blockers from filters after introducing Bottom Tab Navigator #89082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
luacmartins
merged 2 commits into
Expensify:main
from
software-mansion-labs:borys3kk-fix-filter-pills-problems
Apr 28, 2026
+27
−26
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,44 @@ | ||
| import {useIsFocused} from '@react-navigation/native'; | ||
| import {useEffect, useRef} from 'react'; | ||
| import {useEffect} from 'react'; | ||
| import type {SearchQueryJSON} from '@components/Search/types'; | ||
| import {updateAdvancedFilters} from '@libs/actions/Search'; | ||
| import {buildSearchQueryString} from '@libs/SearchQueryUtils'; | ||
| import type {SearchAdvancedFiltersForm} from '@src/types/form'; | ||
|
|
||
| /** | ||
| * Syncs computed filter form values to the SEARCH_ADVANCED_FILTERS_FORM Onyx key | ||
| * whenever they change. Call from SearchAdvanceFiltersButton which already computes formValues | ||
| * via useFilterFormValues. | ||
| * | ||
| * The isFocused guard prevents the blurred (previous) SearchPage instance—kept | ||
| * mounted during navigation transition animations—from overwriting the Onyx form | ||
| * state that was already written by the newly focused instance. | ||
| * | ||
| * On narrow layout (iOS native), navigating to Advanced Filters causes this screen | ||
| * to lose focus. When the user returns, the screen regains focus and this effect | ||
| * would re-fire. Without the prevIsFocusedRef guard below, it would overwrite any | ||
| * form changes made by Advanced Filters (e.g. resetting a date range) with stale | ||
| * values derived from the unchanged URL query parameter. | ||
| * Module-level: tracks the last URL query signature that was synced into the | ||
| * SEARCH_ADVANCED_FILTERS_FORM Onyx key. We deliberately keep this outside the | ||
| * hook so it survives unmount/remount of SearchAdvancedFiltersButton. The | ||
| * button is gated by SearchActionsBarSwitch (`showStatic` flips during | ||
| * `startTransition` after navigation) which causes the hook to remount and | ||
| * would otherwise reset a per-component ref to null — causing the sync to | ||
| * fire again with form values derived from the *old* URL, clobbering any | ||
| * Onyx.merge that was just done by the Advanced Filters flow (e.g. Save Date | ||
| * before the URL has been replaced by View Results). | ||
| */ | ||
| function useSearchFilterSync(formValues: Partial<SearchAdvancedFiltersForm>) { | ||
| let lastSyncedQuerySig: string | null = null; | ||
|
|
||
| /** | ||
| * Syncs computed filter form values to the SEARCH_ADVANCED_FILTERS_FORM Onyx | ||
| * key when the URL query string actually changes. The form is the source for | ||
| * the filter pills shown in the Search header — overwriting it on every | ||
| * re-render (or every fresh mount with the same URL) would erase concurrent | ||
| * Onyx.merge writes from Advanced Filters and leave the pill missing. | ||
| */ | ||
| function useSearchFilterSync(queryJSON: SearchQueryJSON | undefined, formValues: Partial<SearchAdvancedFiltersForm>) { | ||
| const isFocused = useIsFocused(); | ||
| const prevIsFocusedRef = useRef(isFocused); | ||
|
|
||
| useEffect(() => { | ||
| const wasPreviouslyFocused = prevIsFocusedRef.current; | ||
| prevIsFocusedRef.current = isFocused; | ||
|
|
||
| if (!isFocused) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip syncing when just regaining focus to avoid overwriting form | ||
| // changes made while this screen was unfocused (e.g. Advanced Filters). | ||
| if (!wasPreviouslyFocused) { | ||
| const querySig = queryJSON ? buildSearchQueryString(queryJSON) : null; | ||
| if (lastSyncedQuerySig === querySig) { | ||
| return; | ||
| } | ||
|
|
||
| lastSyncedQuerySig = querySig; | ||
| updateAdvancedFilters(formValues, true); | ||
| }, [formValues, isFocused]); | ||
| }, [queryJSON, formValues, isFocused]); | ||
| } | ||
|
|
||
| export default useSearchFilterSync; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard skips all updates when the query signature is unchanged, but
formValuescan change independently of the URL becauseuseFilterFormValuesis derived from async Onyx data (personal details, reports, policy tags/categories) andbuildFilterFormValuesFromQuery()filters against those collections. In cold-load/deeplink flows, the first sync can write an incomplete form; after those collections hydrate, this early return blocks the follow-upupdateAdvancedFilters(..., true), leavingSEARCH_ADVANCED_FILTERS_FORMstale and causing active pills/advanced-filter values to remain missing until the URL query changes.Useful? React with 👍 / 👎.