You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WS Settings - Saving new spend rule briefly displayed then disappear #88453
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
Classification: Frontend bug Causing PR: #86684 - "Add spend rule base page" by @luacmartins (High confidence) Related Issues: #86521
Recommendation: REVERT
PR #86684 introduced the spend rule feature and contains a logic bug in the SpendRulesSection component that causes the newly created rule to disappear immediately after saving, only reappearing after a page refresh.
Assigned: @luacmartins (PR author), @JS00001 (approving reviewer) from highest-confidence causing PR only Labels: DeployBlockerCash kept (frontend App PR is the cause). No label changes made.
📋 Detailed Analysis
Evidence
PR Add spend rule base page #86684 introduced the entire spend rules feature, including SpendRulesSection.tsx and SpendRulePageBase.tsx
The bug matches the symptom exactly: after saving a spend rule, it briefly appears then disappears until a page refresh
The issue is only reproducible on staging (not production), consistent with this being a new feature in the current staging deploy
melvin-bot automatically assigned this issue to the PR's author, confirming PR Add spend rule base page #86684 is the suspected cause
In SpendRulesSection.tsx (lines 124-161), after a rule is saved, the component filters formValues.cardIDs against the live cardsList Onyx value:
constactiveCardIDs=formValues.cardIDs.filter((cardID)=>!!cardsList?.[cardID],);if(activeCardIDs.length===0){returnundefined;// rule is hidden if no active card IDs match}
In SpendRulePageBase.tsx (lines 159-161), the save sequence is:
setExpensifyCardRule(...) — sends optimistic update with the new rule into PRIVATE_EXPENSIFY_CARD_SETTINGS
clearDraftSpendRule() — clears the form
Navigation.goBack() — returns the user to the rules list
The isSpendRulesListLoading guard in SpendRulesSection also checks !expensifyCardSettings?.hasOnceLoaded. The optimistic data written by setExpensifyCardRule does not set hasOnceLoaded: true, so when the user lands back on the list, if cardsList has not yet fully hydrated from Onyx, activeCardIDs resolves to an empty array for the newly created rule, causing the rule to be filtered out (returning undefined). The rule reappears only once the backend response is processed and all Onyx keys are refreshed, which matches the "only displayed correctly after refreshing the page" behavior reported.
Race condition between a WRITE and a READ request. When the user saves a spend rule:
setExpensifyCardRule (a WRITE command) optimistically merges the new rule into PRIVATE_EXPENSIFY_CARD_SETTINGS.cardRules
Navigation.goBack() is called immediately after, remounting SpendRulesSection
SpendRulesSection's unguarded useEffect fires openPolicyExpensifyCardsPage (a READ command)
The server processes the READ before the WRITE completes, so the response doesn't include the newly created rule
The server response overwrites the optimistic data in Onyx, making the rule disappear
The rule reappears on refresh because by then the WRITE has been processed server-side.
What changes do you think we should make in order to solve the problem?
Guard the useEffect in SpendRulesSection.tsx to skip calling openPolicyExpensifyCardsPage when the card settings data has already been loaded. The PRIVATE_EXPENSIFY_CARD_SETTINGS object already has a hasOnceLoaded flag (set in openPolicyExpensifyCardsPage's successData). Check this flag before re-fetching:
// In SpendRulesSection.tsx useEffect:
if (!expensifyCardSettings?.hasOnceLoaded) {
openPolicyExpensifyCardsPage(policyID, defaultFundID);
}
This prevents the redundant READ from firing when navigating back after save, since the data was already loaded when the user first visited the rules page. The optimistic WRITE data will remain intact until the WRITE completes on the server.
What alternative solutions did you explore? (Optional)
An alternative would be to have setExpensifyCardRule's successData re-merge the full rule data (not just clear pendingAction), so even if the READ clobbers it, the WRITE success handler restores it. However, this is fragile — it depends on the WRITE success arriving after the READ response, which isn't guaranteed. Guarding the fetch is simpler and more robust.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
Activity
melvin-bot commentedon Apr 21, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #86684
melvin-bot commentedon Apr 21, 2026
💬 A slack conversation has been started in #expensify-open-source
github-actions commentedon Apr 21, 2026
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
OSBotify commentedon Apr 21, 2026
🔍 Investigation Summary
Classification: Frontend bug
Causing PR: #86684 - "Add spend rule base page" by @luacmartins (High confidence)
Related Issues: #86521
Recommendation: REVERT
PR #86684 introduced the spend rule feature and contains a logic bug in the
SpendRulesSectioncomponent that causes the newly created rule to disappear immediately after saving, only reappearing after a page refresh.Assigned: @luacmartins (PR author), @JS00001 (approving reviewer) from highest-confidence causing PR only
Labels:
DeployBlockerCashkept (frontend App PR is the cause). No label changes made.📋 Detailed Analysis
Evidence
SpendRulesSection.tsxandSpendRulePageBase.tsxVerification
src/pages/workspace/rules/SpendRules/SpendRulesSection.tsxsrc/pages/workspace/rules/SpendRules/SpendRulePageBase.tsxsrc/libs/actions/Card.tsRoot Cause
In
SpendRulesSection.tsx(lines 124-161), after a rule is saved, the component filtersformValues.cardIDsagainst the livecardsListOnyx value:In
SpendRulePageBase.tsx(lines 159-161), the save sequence is:setExpensifyCardRule(...)— sends optimistic update with the new rule intoPRIVATE_EXPENSIFY_CARD_SETTINGSclearDraftSpendRule()— clears the formNavigation.goBack()— returns the user to the rules listThe
isSpendRulesListLoadingguard inSpendRulesSectionalso checks!expensifyCardSettings?.hasOnceLoaded. The optimistic data written bysetExpensifyCardRuledoes not sethasOnceLoaded: true, so when the user lands back on the list, ifcardsListhas not yet fully hydrated from Onyx,activeCardIDsresolves to an empty array for the newly created rule, causing the rule to be filtered out (returningundefined). The rule reappears only once the backend response is processed and all Onyx keys are refreshed, which matches the "only displayed correctly after refreshing the page" behavior reported.MelvinBot commentedon Apr 21, 2026
Proposal
What is the root cause of that problem?
Race condition between a WRITE and a READ request. When the user saves a spend rule:
setExpensifyCardRule(a WRITE command) optimistically merges the new rule intoPRIVATE_EXPENSIFY_CARD_SETTINGS.cardRulesNavigation.goBack()is called immediately after, remountingSpendRulesSectionSpendRulesSection's unguardeduseEffectfiresopenPolicyExpensifyCardsPage(a READ command)The rule reappears on refresh because by then the WRITE has been processed server-side.
What changes do you think we should make in order to solve the problem?
Guard the
useEffectinSpendRulesSection.tsxto skip callingopenPolicyExpensifyCardsPagewhen the card settings data has already been loaded. ThePRIVATE_EXPENSIFY_CARD_SETTINGSobject already has ahasOnceLoadedflag (set inopenPolicyExpensifyCardsPage's successData). Check this flag before re-fetching:This prevents the redundant READ from firing when navigating back after save, since the data was already loaded when the user first visited the rules page. The optimistic WRITE data will remain intact until the WRITE completes on the server.
What alternative solutions did you explore? (Optional)
An alternative would be to have
setExpensifyCardRule'ssuccessDatare-merge the full rule data (not just clearpendingAction), so even if the READ clobbers it, the WRITE success handler restores it. However, this is fragile — it depends on the WRITE success arriving after the READ response, which isn't guaranteed. Guarding the fetch is simpler and more robust.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.JS00001 commentedon Apr 21, 2026
This is prob related to https://github.com/Expensify/Expensify/issues/626628
JS00001 commentedon Apr 21, 2026
This is also disabled on prod, so demoting
IuliiaHerets commentedon Apr 22, 2026
Chrome / v9.3.61-2
Still reproduced
bandicam.2026-04-22.16-18-33-287.mp4
IuliiaHerets commentedon Apr 22, 2026
Tester can't repro this issue anymore
bandicam.2026-04-22.20-25-28-444.mp4
JS00001 commentedon Apr 22, 2026
This was fixed in the be