Search - Creating a new saved search also updates the previously saved search
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.5.36-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/106391 Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Mac 26.5.1 Safari/Chrome App Component: Search
Action Performed:
- Go to https://staging.new.expensify.com
- Navigate to Spend
- Open Filters, set a Merchant filter to Alpha, and select Save
- Save as QA Original, reopen it, and verify the Alpha filter is retained 5, With QA Original selected, change the Merchant filter to Beta
- select Save, and
- choose Create new
- Save as QA Copy
- Reopen the QA Original saved search
Expected Result:
Creating a new saved search should not modify any previously saved searches
Actual Result:
Creating a new saved search also updates the previously saved search
Workaround:
Unknown
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [ ] Windows: Chrome
- [x] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/b8bf9f38-ceb3-4272-9b2e-9541db748130
Applause Internal Information Exported by: Mita Rachim Bug ID: 7310733
Issue Owner
Current Issue Owner: @ZhenjaHorbach
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/ad1e48ead364686b7208302f819a8229ffd07ee1e71e331b6573950c6266f463
🤖 Web test steps verification results: ❌ fail
Reopening QA Original displayed Beta after creating QA Copy, but Reset restored Alpha, indicating remembered unsaved filters rather than an overwritten saved definition. QA has also closed the issue after rechecking.
| Step | Status |
|---|---|
1. Navigate to SpendSpend and Expenses headings were visible. |
✅ |
2. Set Merchant to AlphaFilters displayed Merchant: Contains “Alpha”.![]() |
✅ |
3. Save as QA Original and reopenQA Original reopened with Alpha retained. |
✅ |
4. Change Merchant to BetaQA Original displayed Merchant: Contains “Beta”. |
✅ |
5. Select SaveThe dialog offered updating QA Original or creating a new search. |
✅ |
6. Choose Create newThe naming page opened. |
✅ |
7. Save as QA CopyQA Copy displayed Beta; both saved searches were available. |
✅ |
8. Reopen QA Original and verify Alpha remainsQA Original displayed Beta, failing the reported expectation.Root cause of the displayed behavior: executing the edited query remembers Beta under the original search’s key in SEARCH_FILTERS (Search.ts:1479–1492). Reopening a saved search prefers that remembered query (SearchNavigationUtils.ts:39–49). Alternative checked: Create new does not update the original ID. Its branch opens the naming page, which saves using a fresh ID (SearchFiltersSaveButton.tsx:46–66, SearchSavePage.tsx:201–211). Server persistence was not independently inspected. ![]() |
❌ |
9. Reset QA Original to distinguish remembered edits from its saved definitionReset restored Alpha and removed the Reset/Save controls.Recommendation: No code fix is justified for the withdrawn overwrite report. Remembering unsaved refinements is explicitly covered by an existing navigation test. If creating a copy should also reset the original’s remembered filters, confirm that product requirement separately and add regression coverage distinguishing saved definitions from remembered state. Related context: Add a Save button when a search differs from its default view defines the create/update flow; it is not a confirmed duplicate. ![]() |
✅ |
view run · no recording available
Sorry for the confusion. We have decided to reopen the issue after double-checking all the steps once again.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01867c2936746cf5ca
Proposal
Please re-state the problem that we are trying to solve in this issue.
When editing filters on an existing saved search and selecting "Save" -> "Create new" to save the modified filters as a separate new saved search, the previously saved search also retains the modified filters instead of preserving its original saved criteria.
What is the root cause of that problem?
- When modifying filters on an active saved search (e.g. changing merchant from Alpha to Beta while viewing
QA Original),src/libs/actions/Search.tsoptimistically updates the uncommitted draft query intoONYXKEYS.SEARCH_FILTERS[savedSearch_<originalID>]. - When the user clicks "Save" and selects "Create new" in
SearchFiltersSaveButton.tsx, the user navigates toSearchSavePage.tsx, generating a new saved search ID (rand64()) with the new query and switching the active search key tosavedSearch_<newID>. - However,
ONYXKEYS.SEARCH_FILTERS[savedSearch_<originalID>]is never cleared or reset back to the original saved search query (item.query). - Consequently, when the user navigates back to the previous saved search,
SavedSearchList.tsx:146resolves the query via:
Becauseconst itemQuery = normalizeDatePresetsInQuery(getValidLastQuery(getLastSearchQuery(searchFilters, savedSearchIDToSearchKey(key)), item.query));getLastSearchQuery(searchFilters, ...)returns the uncommitted draft query (Beta),SavedSearchListloads the modified query rather than the saved query (Alpha), causing the original saved search to appear modified.
What changes do you think we should make in order to solve the problem?
- In
src/pages/Search/SearchSavePage.tsx(insideonSaveSearch):- When a new saved search is created branching off an existing active saved search (
activeSavedSearchID), reset or remove the draft uncommitted query fromONYXKEYS.SEARCH_FILTERSfor thatsavedSearchIDToSearchKey(activeSavedSearchID)(e.g., revertingsearchFilters[savedSearchKey]back toactiveSavedSearch.queryor setting it tonull).
- When a new saved search is created branching off an existing active saved search (
- Alternatively, in
SearchFiltersSaveButton.tsx:- When
decision.action === ModalActions.CONFIRM("Create new") is selected, clear or reset the temporary search filters draft foractiveSavedSearchIDbefore callingopenSaveSearchPage().
- When
What alternative solutions did you explore? (Optional)
- Bypassing
getLastSearchQueryinSavedSearchList.tsx: Rejected because draft filter caching is intentional for active exploration, but draft filters should not bleed across when explicitly choosing to fork into a new saved search.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/SearchSavePageTest.tsx or SearchFiltersSaveButtonTest.tsx:
- Add a test verifying that when modifying filters on an active saved search and choosing "Create new", the original saved search's draft in
ONYXKEYS.SEARCH_FILTERSis reset so that reopening the original saved search retains its original query criteria.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Okay Looks like this issue is in prod also But I will check!
https://github.com/user-attachments/assets/d19c4d93-399c-4d1c-9ef9-a3d55d6b2340
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user opens an existing saved search (e.g. QA Original with merchant:Alpha), modifies a filter (e.g. changing merchant to Beta), clicks Save -> Create new, and saves the new search as QA Copy, reopening QA Original from the Saved Searches menu displays the modified Beta filter instead of its original Alpha filter.
What is the root cause of that problem?
- While viewing
QA Original(searchKey = savedSearch_<originalID>), editing a filter dispatchessearch()(src/libs/actions/Search.ts:1504-1514), which optimistically caches the modifiedinputQuery(merchant:Beta) underONYXKEYS.SEARCH_FILTERS[savedSearch_<originalID>].query. - When the user clicks Save and selects Create new in
src/components/Search/SearchPageHeader/SearchFiltersSaveButton.tsx:57-60,SearchSavePage.tsx(onSaveSearch, lines 201-212) creates a new saved search ID (const id = rand64()), callssaveSearch({id, queryJSON: currentSearchQueryJSON, newName}), and updates the route parametersearchKeytosavedSearchIDToSearchKey(id). - However, neither
SearchSavePage.tsxnorsaveSearch()clears or resets the uncommitted draft query stored atONYXKEYS.SEARCH_FILTERS[currentSearchKey](the source saved search from which the user branched Create new). - Worse still, there is a second side effect in
src/components/Search/hooks/useSearchKeyParam.ts:70-82:
Becauseconst savedSearchID = savedSearchIDs.find((id) => { const savedSearchQuery = savedSearches?.[id].query; const lastSavedSearchQuery = getLastSearchQuery(searchFilters, savedSearchIDToSearchKey(id)); return ( (savedSearchQuery ? buildSearchQueryJSON(normalizeDatePresetsInQuery(savedSearchQuery))?.hash === queryJSON?.hash : false) || (lastSavedSearchQuery ? buildSearchQueryJSON(lastSavedSearchQuery)?.hash === queryJSON?.hash : false) ); });searchFilters[savedSearch_<originalID>].querystill has the exact sameBetaquery hash as the newly createdQA Copy,Array.prototype.findmatches<originalID>first wheneversearchKeyis resolved from the query! And when the user clicksQA Originalinsrc/pages/Search/SavedSearchList.tsx:146(ornavigateToFlatNavIteminsrc/libs/SearchNavigationUtils.ts:49),getLastSearchQuery(searchFilters, savedSearchIDToSearchKey(key))returns the staleBetadraft instead ofitem.query(Alpha).
What changes do you think we should make in order to solve the problem?
Clear the remembered draft entry in ONYXKEYS.SEARCH_FILTERS whenever a saved search is saved (both for the target savedSearchIDToSearchKey(id) and, when branching via Create new from an existing saved search, for the source sourceSearchKey):
-
In
src/libs/actions/Search.ts(saveSearch, lines 935-977), accept an optionalsourceSearchKey?: SearchKeyparameter and clear the correspondingONYXKEYS.SEARCH_FILTERSentry (or entries) inoptimisticData:function saveSearch({ id, queryJSON, newName, sourceSearchKey, }: { id: string; queryJSON: Readonly<SearchQueryJSON>; newName?: string; sourceSearchKey?: SearchKey; }) { const normalizedQuery = normalizeDatePresetsInQuery(queryJSON.inputQuery); const savedQueryJSON = normalizedQuery === queryJSON.inputQuery ? queryJSON : (buildSearchQueryJSON(normalizedQuery) ?? queryJSON); const saveSearchName = newName ?? savedQueryJSON?.inputQuery ?? ''; const jsonQuery = JSON.stringify(savedQueryJSON); const targetSearchKey = savedSearchIDToSearchKey(id); const searchFiltersToClear: Record<string, null> = { [targetSearchKey]: null, ...(sourceSearchKey && searchKeyToSavedSearchID(sourceSearchKey) ? {[sourceSearchKey]: null} : {}), }; const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.SAVED_SEARCHES | typeof ONYXKEYS.SEARCH_FILTERS>> = [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.SAVED_SEARCHES}`, value: { [id]: { pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, name: saveSearchName, query: savedQueryJSON.inputQuery, }, }, }, { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.SEARCH_FILTERS, value: searchFiltersToClear, }, ]; -
In
src/pages/Search/SearchSavePage.tsx(lines 198-212), destructurecurrentSearchKeyfromuseSearchQueryContext()and passsourceSearchKey: currentSearchKeyintosaveSearch:const {currentDefaultSearchQueryFilterKeys, currentSearchQueryJSON, currentSearchKey} = useSearchQueryContext(); ... const onSaveSearch = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_SAVE_FORM>) => { if (!currentSearchQueryJSON) { Navigation.goBack(); return; } const id = rand64(); saveSearch({ id, queryJSON: currentSearchQueryJSON, newName: values[INPUT_IDS.NAME].trim(), sourceSearchKey: currentSearchKey, }); Navigation.dismissModal({afterTransition: () => Navigation.setParams({searchKey: savedSearchIDToSearchKey(id)})}); };- If the user opens the Create new page (
SearchSavePage) and presses Back/Cancel without submitting the form,ONYXKEYS.SEARCH_FILTERS[currentSearchKey]remains intact so their in-progress filter edits on the original search are not lost. - Once the user submits Save view on
SearchSavePage, the uncommitted draft onsourceSearchKey(savedSearch_<originalID>) is cleared inONYXKEYS.SEARCH_FILTERS, so reopeningQA Originalloads its savedAlphaquery cleanly.
- If the user opens the Create new page (
What alternative solutions did you explore? (Optional)
- Clearing
ONYXKEYS.SEARCH_FILTERSinsideSearchFiltersSaveButton.tsxas soon as the user clicks Create new in the decision modal: rejected because if the user subsequently cancels/closesSearchSavePagewithout saving the new view, they would lose their unsaved filter edits on the current screen. ClearingsourceSearchKeyinsidesaveSearchupon actual submission ofSearchSavePageavoids data loss on cancel.
Not overdue Will check today
@cocvn157 Stop posting proposals without Help Wanted label Otherwise, you will be banned soon
@ZhenjaHorbach Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
@ZhenjaHorbach Still overdue 6 days?! Let's take care of this!
Not overdue Will check tomorrow
@roryabraham @ZhenjaHorbach this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

