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
Expense - App crashes on creating empty report after deleting default workspace second time. #96946
👋 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.
changed the title [-]Expense-App crashes on creating empty report after deleting default workspace second time.[/-][+]Expense - App crashes on creating empty report after deleting default workspace second time.[/+]on Jul 24, 2026
ℹ️ This crash is the native counterpart of the already‑fixedMaximum update depth exceeded loop (Expensify/App#96411, Expensify/App#96370). PR Expensify/App#96720 (merged 2026‑07‑22, present in v9.4.44) fixed it on web but not on native, which is why it still reproduces on Android/iOS.
What is the root cause of that problem?
Creating a second empty report on a workspace that already owns one opens a confirmation modal, and that modal is opened from an effect whose dependency is an unmemoized callback — producing an infinite re‑render loop that React aborts with Maximum update depth exceeded (a hard crash on native).
Deleting the default workspace forces the "Create report" flow through the workspace‑selector page. There, selectPolicy creates directly the first time, but on the second empty report it takes the setPendingPolicySelection(...) branch, which arms this effect:
useEffect(() => {
if (!pendingPolicySelection) return;
openCreateReportConfirmation();
}, [pendingPolicySelection, openCreateReportConfirmation]); // ← callback identity in deps
openCreateReportConfirmation is a plain arrow function (useCreateEmptyReportConfirmation.tsx:79) whose identity depends on the values from useConfirmModal / ModalContext. Opening the modal calls setModalStack, which re‑renders ModalProvider and produces a new provider value object (ModalContext.tsx:138) → consumers re‑render → new openCreateReportConfirmation identity → the effect re‑fires while pendingPolicySelection is still set → the modal reopens → loop.
Why v9.4.44 still crashes on native even though Expensify/App#96720 is in the build: that PR stabilized the ModalContext value by moving resolveModal to a modalStackRef and relying on React Compiler to auto‑memoize the provider value. Per this repo's compiler setup, the web (OXC) and native (Babel) compilers "do not always agree, so a file can be memoized on one platform but not the other." The web build got the memoization and stopped looping; the native build did not, so the loop — and the crash — survive on Android and iOS. This also explains "Reproducible in production: No" — the empty‑report‑confirmation path only exists on staging.
Evidence & investigation details
Repro is functionally identical to Expensify/App#96370 (iOS) and the web report Expensify/App#96411: make a non‑default workspace the effective default (by deleting the default), then create the same workspace's empty report twice.
The Expensify/App#96720 ModalContext ref‑fix is present in the v9.4.44 checkout (modalStackRef at ModalContext.tsx:57, resolveModal reads modalStackRef.current.modals at :98) — yet the crash still reproduces, confirming the fix is incomplete for native.
showConfirmModal/closeModal come from useConfirmModal, which wraps the ModalContext value; none are wrapped in explicit useCallback/useMemo, so their stability depends entirely on the compiler.
The direct createNewReport path itself is null‑safe against a deleted/undefined active policy, so this is a render‑loop crash, not a null‑deref.
Closed alternative fixes on Expensify/App#96411 — PR Expensify/App#96481 (page‑level ref) and PR Expensify/App#96484 (useEffectEvent) — targeted exactly this effect before Expensify/App#96720 was chosen instead.
Not runtime‑confirmed: I have not pulled a crash stack for this specific report, so I can't be 100% certain the native crash message is literally Maximum update depth exceeded vs. another symptom of the same loop. A Sentry/BrowserStack stack from the v9.4.44 session would confirm decisively.
What changes do you think we should make in order to solve the problem?
Make the fix compiler‑independent instead of relying on React Compiler memoization that only holds on web:
Explicitly memoize the ModalContext provider value with useMemo, and wrap showModal/closeModal/resolveModal in useCallback in ModalContext.tsx, so the value is stable on all platforms.
Belt‑and‑suspenders at the trigger site: remove openCreateReportConfirmation from the effect's dependency array in DynamicNewReportWorkspaceSelectionPage.tsx:186 — call it via a useEffectEvent/ref so the effect only depends on pendingPolicySelection (this is the approach the closed PR Expensify/App#96484 used).
Either change alone should stop the loop; doing both removes the dependency on cross‑platform compiler behavior. Since this is a deploy blocker, option 1 fixes the root shared component; option 2 hardens the specific crash path.
What alternative solutions did you explore? (Optional)
Reverting Expensify/App#96720 is not appropriate — it's a partial fix, and reverting would re‑break web. Wrapping only openCreateReportConfirmation in useCallback is insufficient on its own because its dependencies (showConfirmModal/closeModal) are themselves unstable unless the ModalContext value is memoized.
Related issues:Expensify/App#96411 (web, fixed by PR Expensify/App#96720), Expensify/App#96370 (iOS, same loop, still open). These three are the same underlying bug.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/96946) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
yuwenmemon — it's Expensify/App#96700, not Expensify/App#96720.
Expensify/App#96720 is a fix (for the earlier Expensify/App#96411 loop) that only stabilizes ModalContext — it has no platform branch and doesn't touch the Search render path this crash lives in. Expensify/App#96700 ("Fix empty view shows briefly when sorting") is the regression. dmkt9's bisection confirms it empirically: reverting Expensify/App#96700 (with Expensify/App#96720 still in place) stops the repro.
⚠️ This corrects my earlier proposal above, which wrongly blamed Expensify/App#96720 as a "partial/native-only" fix — that theory doesn't hold up against the code.
Mechanism:Expensify/App#96700 rewrote isSearchDataLoaded to stop comparing the stable queryJSON.hash and instead recompute the hash every render from the mutable snapshot fields searchResults.search.sortBy/sortOrder (via getQueryHashes(...).primaryHash). During the optimistic empty-report create, those snapshot fields settle across Onyx merges, so the recomputed hash oscillates against search.hash → isDataLoaded flips loaded↔not-loaded → sortedData gets a new reference each render → the setState effect in useStableOptimisticSortedData.ts:91-140 re-fires every render → "Maximum update depth exceeded", which is a hard crash on Hermes/native (a red overlay on web dev, and absent in production which still has the pre-#96700 stable check — matching "not reproducible in production").
Recommendation: revert or fix Expensify/App#96700 so isSearchDataLoaded doesn't derive an unstable hash mid-optimistic-write (e.g. compare against queryJSON.hash directly, or memoize the recomputed hash so it can't flip while the snapshot churns). Do not revert Expensify/App#96720 — that would just re-break Expensify/App#96411.
Evidence & confidence
#96720 is orthogonal: it only edited ModalContext.tsx (modalStack → ref). No web/native branching, so the "memoized on web but not native" idea from my earlier proposal has no basis in that file. useCreateEmptyReportConfirmation also already ref-stabilizes its callbacks, so the effect at DynamicNewReportWorkspaceSelectionPage.tsx:186-192 isn't the unstable-callback loop I claimed.
#96700 is the only change on the failing path: it touched SearchUIUtils.ts / SearchQueryUtils.ts / SearchResultsProvider.tsx / SearchResults.ts. getQueryHashes folds sortBy/sortOrder into primaryHash, and #96700 added those fields to defaultSearchInfo — so the "loaded" check became a moving target.
Empirical revert by dmkt9 isolates #96700 while #96720 stayed in the build.
Confidence: medium‑high. The client-log attachment on this issue is truncated (only generic Onyx entries), so I couldn't pull the literal fatal string. A Sentry/BrowserStack JS stack from the v9.4.44 Android session showing Maximum update depth exceeded with useStableOptimisticSortedData/useSearchSnapshot in the frames would make this conclusive.
Activity
applause-bot commentedon Jul 24, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/0213a37d1006a1c5efc8379a5b80966430a274ab24101ee875011ff3469685e6
https://platform.applause.com/services/links/v1/external/3f79912da53967f32308738cbe8cd92878a950a18aca2f083f07ab206660a56b
melvin-bot commentedon Jul 24, 2026
Triggered auto assignment to @mollfpr (
DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.melvin-bot commentedon Jul 24, 2026
💬 A slack conversation has been started in #expensify-open-source
github-actions commentedon Jul 24, 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:
[-]Expense-App crashes on creating empty report after deleting default workspace second time.[/-][+]Expense - App crashes on creating empty report after deleting default workspace second time.[/+]MelvinBot commentedon Jul 24, 2026
Proposal
What is the root cause of that problem?
Creating a second empty report on a workspace that already owns one opens a confirmation modal, and that modal is opened from an effect whose dependency is an unmemoized callback — producing an infinite re‑render loop that React aborts with
Maximum update depth exceeded(a hard crash on native).Deleting the default workspace forces the "Create report" flow through the workspace‑selector page. There,
selectPolicycreates directly the first time, but on the second empty report it takes thesetPendingPolicySelection(...)branch, which arms this effect:(
DynamicNewReportWorkspaceSelectionPage.tsx:186-192)openCreateReportConfirmationis a plain arrow function (useCreateEmptyReportConfirmation.tsx:79) whose identity depends on the values fromuseConfirmModal/ModalContext. Opening the modal callssetModalStack, which re‑rendersModalProviderand produces a new provider value object (ModalContext.tsx:138) → consumers re‑render → newopenCreateReportConfirmationidentity → the effect re‑fires whilependingPolicySelectionis still set → the modal reopens → loop.Why v9.4.44 still crashes on native even though
Expensify/App#96720is in the build: that PR stabilized theModalContextvalue by movingresolveModalto amodalStackRefand relying on React Compiler to auto‑memoize the provider value. Per this repo's compiler setup, the web (OXC) and native (Babel) compilers "do not always agree, so a file can be memoized on one platform but not the other." The web build got the memoization and stopped looping; the native build did not, so the loop — and the crash — survive on Android and iOS. This also explains "Reproducible in production: No" — the empty‑report‑confirmation path only exists on staging.Evidence & investigation details
Expensify/App#96370(iOS) and the web reportExpensify/App#96411: make a non‑default workspace the effective default (by deleting the default), then create the same workspace's empty report twice.Expensify/App#96720ModalContext ref‑fix is present in the v9.4.44 checkout (modalStackRefatModalContext.tsx:57,resolveModalreadsmodalStackRef.current.modalsat:98) — yet the crash still reproduces, confirming the fix is incomplete for native.showConfirmModal/closeModalcome fromuseConfirmModal, which wraps theModalContextvalue; none are wrapped in explicituseCallback/useMemo, so their stability depends entirely on the compiler.createNewReportpath itself is null‑safe against a deleted/undefined active policy, so this is a render‑loop crash, not a null‑deref.Expensify/App#96411— PRExpensify/App#96481(page‑level ref) and PRExpensify/App#96484(useEffectEvent) — targeted exactly this effect beforeExpensify/App#96720was chosen instead.Not runtime‑confirmed: I have not pulled a crash stack for this specific report, so I can't be 100% certain the native crash message is literally
Maximum update depth exceededvs. another symptom of the same loop. A Sentry/BrowserStack stack from the v9.4.44 session would confirm decisively.What changes do you think we should make in order to solve the problem?
Make the fix compiler‑independent instead of relying on React Compiler memoization that only holds on web:
ModalContextprovider value withuseMemo, and wrapshowModal/closeModal/resolveModalinuseCallbackinModalContext.tsx, so the value is stable on all platforms.openCreateReportConfirmationfrom the effect's dependency array inDynamicNewReportWorkspaceSelectionPage.tsx:186— call it via auseEffectEvent/ref so the effect only depends onpendingPolicySelection(this is the approach the closed PRExpensify/App#96484used).Either change alone should stop the loop; doing both removes the dependency on cross‑platform compiler behavior. Since this is a deploy blocker, option 1 fixes the root shared component; option 2 hardens the specific crash path.
What alternative solutions did you explore? (Optional)
Reverting
Expensify/App#96720is not appropriate — it's a partial fix, and reverting would re‑break web. Wrapping onlyopenCreateReportConfirmationinuseCallbackis insufficient on its own because its dependencies (showConfirmModal/closeModal) are themselves unstable unless theModalContextvalue is memoized.Related issues:
Expensify/App#96411(web, fixed by PRExpensify/App#96720),Expensify/App#96370(iOS, same loop, still open). These three are the same underlying bug.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/96946)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
mollfpr commentedon Jul 24, 2026
@dmkt9 @jayeshmangwani could you check this blocker? It seems related to the PR #96720
dmkt9 commentedon Jul 24, 2026
Hi @mollfpr, I've just taken a look. It seems this bug was introduced by #96700. After reverting that PR, I can no longer reproduce the issue.
aimane-chnaif commentedon Jul 24, 2026
@dmkt9 are you able to reproduce on latest
main?dmkt9 commentedon Jul 24, 2026
@aimane-chnaif I'm not sure. I haven't tested it on the latest
mainyet.yuwenmemon commentedon Jul 24, 2026
@MelvinBot what do you think? Is #96720 the root cause or is #96700?
MelvinBot commentedon Jul 24, 2026
yuwenmemon— it'sExpensify/App#96700, notExpensify/App#96720.Expensify/App#96720is a fix (for the earlierExpensify/App#96411loop) that only stabilizesModalContext— it has no platform branch and doesn't touch the Search render path this crash lives in.Expensify/App#96700("Fix empty view shows briefly when sorting") is the regression.dmkt9's bisection confirms it empirically: revertingExpensify/App#96700(withExpensify/App#96720still in place) stops the repro.Expensify/App#96720as a "partial/native-only" fix — that theory doesn't hold up against the code.Mechanism:
Expensify/App#96700rewroteisSearchDataLoadedto stop comparing the stablequeryJSON.hashand instead recompute the hash every render from the mutable snapshot fieldssearchResults.search.sortBy/sortOrder(viagetQueryHashes(...).primaryHash). During the optimistic empty-report create, those snapshot fields settle across Onyx merges, so the recomputed hash oscillates againstsearch.hash→isDataLoadedflips loaded↔not-loaded →sortedDatagets a new reference each render → thesetStateeffect inuseStableOptimisticSortedData.ts:91-140re-fires every render → "Maximum update depth exceeded", which is a hard crash on Hermes/native (a red overlay on web dev, and absent in production which still has the pre-#96700stable check — matching "not reproducible in production").Recommendation: revert or fix
Expensify/App#96700soisSearchDataLoadeddoesn't derive an unstable hash mid-optimistic-write (e.g. compare againstqueryJSON.hashdirectly, or memoize the recomputed hash so it can't flip while the snapshot churns). Do not revertExpensify/App#96720— that would just re-breakExpensify/App#96411.Evidence & confidence
#96720is orthogonal: it only editedModalContext.tsx(modalStack → ref). No web/native branching, so the "memoized on web but not native" idea from my earlier proposal has no basis in that file.useCreateEmptyReportConfirmationalso already ref-stabilizes its callbacks, so the effect atDynamicNewReportWorkspaceSelectionPage.tsx:186-192isn't the unstable-callback loop I claimed.#96700is the only change on the failing path: it touchedSearchUIUtils.ts/SearchQueryUtils.ts/SearchResultsProvider.tsx/SearchResults.ts.getQueryHashesfoldssortBy/sortOrderintoprimaryHash, and#96700added those fields todefaultSearchInfo— so the "loaded" check became a moving target.dmkt9isolates#96700while#96720stayed in the build.Maximum update depth exceededwithuseStableOptimisticSortedData/useSearchSnapshotin the frames would make this conclusive.aimane-chnaif commentedon Jul 24, 2026
Is this still reproducible on latest staging 9.4.44-2?
m-natarajan commentedon Jul 25, 2026
Unable to repro, Pixel 4/Android 13, v9.4.44-6
az_recorder_20260724_213836.mp4
yuwenmemon commentedon Jul 25, 2026
@aimane-chnaif - Look at that you're smarter than @MelvinBot 😉