-
Notifications
You must be signed in to change notification settings - Fork 3.9k
reset default query on errors #67991
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
dangrous
merged 4 commits into
Expensify:main
from
huult:67295-reset-default-query-on-errors
Aug 18, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7faed0
reset default query on error or clear cache
huult c74dad2
reset shouldResetSearchQuery flag when creating a new search
huult 5db2511
Merge remote-tracking branch 'upstream/main' into 67295-reset-default…
huult 4bcf95d
Merge remote-tracking branch 'upstream/main' into 67295-reset-default…
huult 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
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 |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNa | |
| import Performance from '@libs/Performance'; | ||
| import {getIOUActionForTransactionID, isExportIntegrationAction, isIntegrationMessageAction} from '@libs/ReportActionsUtils'; | ||
| import {canEditFieldOfMoneyRequest, generateReportID, isArchivedReport} from '@libs/ReportUtils'; | ||
| import {buildSearchQueryString} from '@libs/SearchQueryUtils'; | ||
| import {buildCannedSearchQuery, buildSearchQueryString} from '@libs/SearchQueryUtils'; | ||
| import { | ||
| getListItem, | ||
| getSections, | ||
|
|
@@ -162,6 +162,8 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS | |
| shouldShowSelectAllMatchingItems, | ||
| areAllMatchingItemsSelected, | ||
| selectAllMatchingItems, | ||
| shouldResetSearchQuery, | ||
| setShouldResetSearchQuery, | ||
| } = useSearchContext(); | ||
| const [offset, setOffset] = useState(0); | ||
|
|
||
|
|
@@ -630,6 +632,19 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS | |
|
|
||
| const hasErrors = Object.keys(searchResults?.errors ?? {}).length > 0 && !isOffline; | ||
|
|
||
| useEffect(() => { | ||
| const currentRoute = Navigation.getActiveRouteWithoutParams(); | ||
| if (hasErrors && (currentRoute === '/' || (shouldResetSearchQuery && currentRoute === '/search'))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @huult Could you please explain the conditions? |
||
| // Use requestAnimationFrame to safely update navigation params without overriding the current route | ||
| requestAnimationFrame(() => { | ||
| Navigation.setParams({q: buildCannedSearchQuery()}); | ||
| }); | ||
| if (shouldResetSearchQuery) { | ||
| setShouldResetSearchQuery(false); | ||
| } | ||
| } | ||
| }, [hasErrors, queryJSON, searchResults, shouldResetSearchQuery, setShouldResetSearchQuery]); | ||
|
|
||
| const fetchMoreResults = useCallback(() => { | ||
| if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems) { | ||
| return; | ||
|
|
||
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
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.
@huult Could you please explain why this is needed?
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.
For case 3, I used a flag to control resetting the query to the default. As I checked, we don’t have any flag to indicate when the app restarts, so I introduced this flag to differentiate between restarting the app or using the top-right corner search. This ensures the query is reset correctly.
This condition means that if we have an error, the search route is not initialized, and the search page is already mounted, then the query should be reset. This prevents the case where a search error occurs but no error page is displayed because the error was reset. This condition ensures that scenario is handled correctly.
Next, when we have an error but the search data is undefined due to restarting the app, we must wait for the search route to initialize before resetting the query. Therefore, we need a flag to determine when the query should be reset.
Lastly, when we restart the app and use the top-right corner search with a valid query, we don’t need to reset the query. This condition handles that case.
Open the Expensify app.
Navigate to the Reports tab.
Enter a search query, for example: type:abcd.
Switch to another tab, such as Workspace or Account, or go to Account → Troubleshoot → Clear cache and restart.
Tap the Search icon at the top-right corner and search for something (e.g., abcd).
Verify that: