Skip to content

Freeze non top screens to prevent extra-rerenders 2#85443

Open
VickyStash wants to merge 7 commits intoExpensify:mainfrom
callstack-internal:VickyStash/refactor/freeze-non-top-screens-2
Open

Freeze non top screens to prevent extra-rerenders 2#85443
VickyStash wants to merge 7 commits intoExpensify:mainfrom
callstack-internal:VickyStash/refactor/freeze-non-top-screens-2

Conversation

@VickyStash
Copy link
Contributor

@VickyStash VickyStash commented Mar 16, 2026

Explanation of Change

Freezes non-top screens in the navigation stack to prevent unnecessary re-renders, using a ScreenFreezeWrapper for the split navigator on web and a react-navigation patch for mobile.

Previous PR #82764 was reverted #85198 with the next blockers:

$ #85184
$ #85185
$ #85149
$ #85170
$ #85250

Fixed Issues

$ #33725
PROPOSAL: https://expensify.slack.com/archives/C05LX9D6E07/p1771428903641059

Tests

  • Verify that no errors appear in the JS console
  1. Open the app
  2. Go to the Inbox tab
  3. WEB: switch between several reports, make sure it works as expected, no lagging
  4. Open any chat with a couple of expenses
  5. Open expenses overview
  6. Create one more expense there
  7. Swipe/Go back to the chat, see if the chat is updated
  8. WEB: Open chat details by tapping on the header, make sure the underlying chat screen is visible. Return back.
  9. MOBILE: Open emoji modal, make sure underlying chat screen is visible. Return back.
  10. Go to Settings > Workspace > Members > Member details and all the way back. Make sure it works as expected

#85184 — Web: App freezes when clicking "Go to Expensify Cards" button

Preconditions: Have a workspace with Expensify cards enabled. At least one Expensify card is assigned with the limit type set to Smart limit.

  1. Navigate to the app
  2. Go to workspace settings > More features > Workflows
  3. Click on the locked toggle switch
  4. Click on the "Go to Expensify Cards" button
  5. Verify the app redirects to the Expensify Card tab and is fully functional (no freeze)

#85185 — iOS: App becomes unresponsive when changing Copilot access

Preconditions: Account has a copilot set.

  1. Open the app
  2. Go to Account > Security > Copilot
  3. Tap the 3-dot menu near the copilot
  4. Tap "Change access level"
  5. Verify the app remains responsive and you can change access or tap back

#85149 — Web: ENTER on Merchant opens Schedule Call after visiting #admins

  1. Log in with a new Gmail account
  2. Create a workspace
  3. Go to #admins
  4. Go to workspace chat
  5. Click + > Create expense > Manual
  6. Enter amount
  7. Click Merchant
  8. Enter merchant and press Enter
  9. Verify RHP returns to the confirm page (not Schedule Call)

#85170 — iOS: Workspace settings gray out briefly after swiping back

  1. Launch Expensify app
  2. Go to workspace settings > More features (or any page in workspace settings)
  3. Swipe back to return to workspace settings
  4. Verify workspace settings do not gray out briefly

#85250 — iOS: App freezes on downgrade workspace page

  1. Launch Hybrid app
  2. Create a new Gmail account
  3. On onboarding, select "Manage my team's expenses" > 1-10 option
  4. Select either NetSuite, Sage Intacct, or QBD accounting software (upgrades to Control WS)
  5. Tap Continue & finish onboarding
  6. Go to Account > Subscriptions > "Explore all plans" button
  7. Select "Downgrade to Collect"
  8. Tap "Downgrade Workspace" or try tapping the back button
  9. Verify the app does not freeze and the downgrade proceeds normally

Offline tests

Same, as in the Tests section

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

Same, as in the Tests section

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.mp4
Android: mWeb Chrome
android_web.mp4
iOS: Native
ios.mov
ios-85250.mov
ios-85170.mov
ios-85185.mp4
iOS: mWeb Safari
ios_web.mov
MacOS: Chrome / Safari
web.mp4
web-85149.mp4
web-85184.mp4

@github-actions
Copy link
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@VickyStash VickyStash changed the title Vicky stash/refactor/freeze non top screens 2 Freeze non top screens to prevent extra-rerenders 2 Mar 16, 2026
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/hooks/useKeyboardShortcut.ts 100.00% <100.00%> (ø)
...gation/AppNavigator/createSplitNavigator/index.tsx 100.00% <ø> (ø)
...formStackNavigatorComponent/ScreenFreezeContext.ts 100.00% <100.00%> (ø)
src/setup/index.ts 100.00% <100.00%> (ø)
...ntModalScreen/AttachmentModalBaseContent/index.tsx 89.65% <0.00%> (+1.01%) ⬆️
...kspace/members/WorkspaceInviteMessageComponent.tsx 0.00% <0.00%> (ø)
...ormStackNavigatorComponent/ScreenFreezeWrapper.tsx 0.00% <0.00%> (ø)
...on/createPlatformStackNavigatorComponent/index.tsx 0.00% <0.00%> (ø)
... and 16 files with indirect coverage changes

@VickyStash
Copy link
Contributor Author

FYI, there is a bug with newly created account for gmail user - I can't pass through the onboarding modal. This happens on main too, so it's not related to current pr:

main-bug-onboarding.mp4

@VickyStash VickyStash marked this pull request as ready for review March 17, 2026 13:40
@VickyStash VickyStash requested review from a team as code owners March 17, 2026 13:40
@melvin-bot melvin-bot bot requested review from situchan and removed request for a team March 17, 2026 13:40
@melvin-bot
Copy link

melvin-bot bot commented Mar 17, 2026

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested review from joekaufmanexpensify and removed request for a team March 17, 2026 13:40
@situchan
Copy link
Contributor

@MelvinBot please post summary of new changes which fix regressions from v1 PR.

useLayoutEffect(() => {
// When unfreezing, always apply immediately so the screen is visible right away.
if (!isScreenBlurred) {
// eslint-disable-next-line react-hooks/set-state-in-effect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-5 (docs)

The eslint-disable-next-line react-hooks/set-state-in-effect suppression lacks an explicit justification for why the lint rule is safe to bypass here. The preceding comment describes the intended behavior but does not explain why calling setFrozen synchronously inside useLayoutEffect will not cause re-render loops.

Add a comment directly explaining why the rule is safe to disable, for example:

// eslint-disable-next-line react-hooks/set-state-in-effect -- Synchronous unfreeze is intentional; the early return prevents infinite loops since isScreenBlurred is the only dependency and won't change as a result of this setState.
setFrozen(false);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

}

// No blockers or overlays — freeze immediately.
// eslint-disable-next-line react-hooks/set-state-in-effect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-5 (docs)

The eslint-disable-next-line react-hooks/set-state-in-effect suppression lacks an explicit justification for why the lint rule is safe to bypass here. The preceding comment describes the intent but does not explain why calling setFrozen inside useLayoutEffect will not cause re-render loops.

Add a comment directly explaining why the rule is safe to disable, for example:

// eslint-disable-next-line react-hooks/set-state-in-effect -- Synchronous freeze is safe; isScreenBlurred is the only dependency and setFrozen(true) won't trigger further isScreenBlurred changes.
setFrozen(isScreenBlurred);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@MelvinBot
Copy link
Contributor

Summary of New Changes Fixing v1 Regressions

This PR re-applies the original v1 PR (#82764) and adds three fix commits on top to address the five regressions that caused the revert. Here's what each fix does:


1. Fix for #85184 — Web: App freezes when clicking "Go to Expensify Cards" button

Commit: 611e70e | File: ScreenFreezeWrapper.tsx

The original ScreenFreezeWrapper only deferred freezing when a tooltip was active. It didn't account for modals. When a modal was still open during a navigation transition, the screen behind it would freeze, causing the app to become unresponsive.

Fix: Added an areAllModalsHidden() check. Now freezing is deferred by one frame whenever a modal or tooltip is still open, giving them time to dismiss before the tree is suspended. Also restructured the logic to always unfreeze immediately (no deferral needed when making a screen visible).


2. Fix for #85170, #85185, #85250 — iOS: Gray-out on swipe-back, Copilot unresponsive, Downgrade freeze

Commit: 390daa4 | File: react-native-screens patch (DelayedFreeze)

All three iOS issues shared the same root cause: on Fabric, the DelayedFreeze in react-native-screens was freezing screens too soon — before transition/dismiss animations finished. The original v1 patch used setTimeout(0) + requestAnimationFrame, which wasn't enough delay for iOS animations.

Fix: Introduced a FREEZE_DELAY_MS = 400 ms delay before the requestAnimationFrame. This ensures that screen transition animations, popover dismissals, and swipe-back gestures have enough time to complete before React suspends the tree.


3. Fix for #85149 — Web: ENTER on Merchant opens Schedule Call after visiting #admins

Commit: 2c92405 | Files: useKeyboardShortcut.ts, ScreenFreezeContext.ts (new), ScreenFreezeWrapper.tsx

When a screen was frozen, its keyboard shortcuts were supposed to unsubscribe via cleanup effects. But the freeze happened before cleanup could run, leaving stale shortcuts from a previously visited screen (e.g., #admins' "Schedule Call" shortcut) still active. Pressing Enter would trigger that stale shortcut instead of the expected action.

Fix: Introduced a freeze defer mechanism:

  • New ScreenFreezeContext provides a registerFreezeDefer() API
  • useKeyboardShortcut registers a defer while its shortcut is active
  • ScreenFreezeWrapper checks for active defers before freezing — if any exist, it delays freezing by one frame so cleanup effects (shortcut unsubscription) can run first

TL;DR: The three fix commits address: (1) modal-awareness in freeze logic, (2) a longer delay for iOS native animations before freezing, and (3) a defer mechanism so keyboard shortcut cleanup runs before screens are frozen.

@MelvinBot
Copy link
Contributor

Code Review: Freeze non-top screens v2

Overall this is a well-structured approach to preventing unnecessary re-renders. The ScreenFreezeWrapper for web and the react-native-screens/react-navigation patches for native are a clean separation. I found a few issues worth discussing:


1. contextValue not memoized in ScreenFreezeWrapper (Performance)

File: ScreenFreezeWrapper.tsx:19-27

registerFreezeDefer and contextValue are recreated on every render without useCallback/useMemo:

const registerFreezeDefer = () => { ... };
const contextValue = {registerFreezeDefer};

Since contextValue is a new object reference every render, all consumers of useScreenFreezeContext() (currently every useKeyboardShortcut call inside split navigator screens) will re-render whenever ScreenFreezeWrapper renders — even if nothing meaningful changed. This is counterproductive for a component whose purpose is to prevent unnecessary re-renders.

Suggested fix:

const registerFreezeDefer = useCallback(() => {
    freezeDeferCountRef.current++;
    return () => { freezeDeferCountRef.current--; };
}, []);

const contextValue = useMemo(() => ({registerFreezeDefer}), [registerFreezeDefer]);

2. Potential timing race in AttachmentModalBaseContent on native (Correctness)

File: AttachmentModalBaseContent/index.tsx:169-173

onClose?.();
requestAnimationFrame(() => {
    onConfirm?.(Object.assign(files ?? {}, {source} as FileObject));
});

The comment says the rAF deferral gives "the target screen time to unfreeze and re-mount its refs." However, the DelayedFreeze patch delays both freezing and unfreezing by FREEZE_DELAY_MS (400ms) + 1 rAF (~416ms total). When onClose triggers goBack(), the report screen below starts unfreezing — but that takes ~416ms. The requestAnimationFrame fires in ~16ms, well before the screen unfreezes.

If the report screen was frozen by the native stack (since the react-navigation patch now freezes all non-focused screens on Fabric), composerRef.current could still be null when addAttachment runs, which throws: "The composerRef.clearWorklet function is not set yet."

Could you verify this doesn't happen on iOS/Android? The navigation hierarchy may prevent this (if the attachment modal and report screen are in different navigators), but the timing math is concerning.

Also: there is no cancelAnimationFrame cleanup — if the component unmounts before the rAF fires, onConfirm still executes with potentially stale closures.


3. wrappedDescriptors computed inline without useMemo (Performance)

File: createPlatformStackNavigatorComponent/index.tsx:108-122

The for loop creates new descriptor objects and new render arrow functions on every render. Since wrappedDescriptors is in the Content useMemo dependency array, the memo never caches — it recomputes every render.

Note: descriptors from React Navigation's useDescriptors is also unstable (rebuilt with reduce() every render), so this isn't strictly worse than the baseline. But wrapping in useMemo would still avoid unnecessary object allocations:

const wrappedDescriptors = useMemo(() => {
    if (!freezeNonTopScreens) return descriptors;
    const topRouteKey = state.routes[state.index]?.key;
    // ... wrapping logic
}, [descriptors, state.index, persistentScreens]);

4. DelayedFreeze delays unfreezing too (Design question)

File: react-native-screens+4.15.4+001+delay-freeze-until-paint.patch

The effect uses the same FREEZE_DELAY_MS = 400 for both freeze and unfreeze transitions:

React.useEffect(() => {
    const id = setTimeout(() => {
        rafID = requestAnimationFrame(() => setFreezeState(freeze));
    }, FREEZE_DELAY_MS);
    ...
}, [freeze]);

When navigating back to a frozen screen, the unfreeze is delayed by ~416ms. Is this intentional? The 400ms delay was motivated by needing animations to complete before freezing, but for unfreezing, the user is navigating TO this screen and would benefit from immediate responsiveness.

Consider only applying the delay when freeze is true:

React.useEffect(() => {
    if (!freeze) {
        setFreezeState(false); // Unfreeze immediately
        return;
    }
    const id = setTimeout(() => {
        rafID = requestAnimationFrame(() => setFreezeState(true));
    }, FREEZE_DELAY_MS);
    return () => { clearTimeout(id); cancelAnimationFrame(rafID); };
}, [freeze]);

This mirrors the approach in ScreenFreezeWrapper on web, which already unfreezes immediately.


5. Minor observations

  • FREEZE_DELAY_MS = 400: This is a heuristic that assumes all animations complete within 400ms. React Navigation's default iOS animation is 350ms, so 400ms has a 50ms margin. On slower devices this could be tight. Consider whether InteractionManager.runAfterInteractions would be more deterministic.
  • registerFreezeDefer not in useEffect deps (useKeyboardShortcut.ts:71): The eslint-disable already covers this, and it's harmless since the function identity changes but the behavior is the same. Just noting it for awareness.
  • freezeNonTopScreens silently ignored on native: index.native.tsx doesn't read this option. The native path uses the react-native-screens/react-navigation patches instead. This separation is correct but may confuse future contributors — a brief comment in the type definition would help.

Summary

# Issue Severity Type
1 contextValue not memoized — causes re-renders of all keyboard shortcut consumers in split screens Medium Performance
2 rAF timing in submitAndClose may fire before native DelayedFreeze unfreezes target screen Medium Correctness
3 wrappedDescriptors not memoized Low Performance
4 DelayedFreeze delays unfreezing by 400ms — should unfreeze immediately Medium Design
5 Minor: magic number, missing dep, missing comment Low Code quality

Items 1 and 4 seem most actionable. The rest are worth discussing but may be acceptable tradeoffs.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5450de216

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +29 to +31
+ const id = setTimeout(() => {
+ rafID = requestAnimationFrame(() => setFreezeState(freeze));
+ }, FREEZE_DELAY_MS);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Unfreeze screens immediately when focus returns

This effect now waits FREEZE_DELAY_MS for all freeze transitions, not just when entering the frozen state. When a route becomes focused again (freeze flips true -> false), setFreezeState(false) is delayed by ~400ms, so the newly focused screen can remain suspended and miss immediate UI updates/taps after back/pop navigation. The delay should only apply when freeze is true, while unfreezing should happen immediately.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DelayedFreeze if freeze is false it always applied right away, https://github.com/software-mansion/react-native-screens/blob/63b3baab65a1fd36da04ae426f98ad460217e1e0/src/components/helpers/DelayedFreeze.tsx#L24

  return <Freeze freeze={freeze ? freezeState : false}>{children}</Freeze>;

@VickyStash
Copy link
Contributor Author

Melvin's comments don't look accurate to me, as it thinks that unfreezing is delayed too, but it's not, as I've mentioned here #85443 (comment).
Also, we don't memoize the values anymore as it handled by react compiler

@situchan
Copy link
Contributor

Currently blocked hybrid iOS testing https://expensify.slack.com/archives/C05LX9D6E07/p1773753991898119

@joekaufmanexpensify joekaufmanexpensify removed their request for review March 17, 2026 21:46
@joekaufmanexpensify
Copy link
Contributor

No product review needed

@VickyStash
Copy link
Contributor Author

Currently blocked hybrid iOS testing https://expensify.slack.com/archives/C05LX9D6E07/p1773753991898119

@situchan it's not blocked anymore

@VickyStash
Copy link
Contributor Author

Hey @situchan, any ETA on this one?

@situchan
Copy link
Contributor

Please merge main. I'll review today

@VickyStash
Copy link
Contributor Author

@situchan kind bump here, since I'll be OOO March 25-27 next week

@situchan
Copy link
Contributor

I've been testing this from yesterday. Will update shortly

@situchan
Copy link
Contributor

situchan commented Mar 21, 2026

iOS: app crashes immediately after creating new account
(I confirmed multiple times that's caused by this PR)

crash.mov

@situchan
Copy link
Contributor

@MelvinBot can you investigate #85443 (comment)?

@MelvinBot
Copy link
Contributor

🔍 Investigation: iOS crash after creating new account

Confidence: Medium-High (code evidence is strong, but no native crash stack trace to fully confirm)

Root Cause

The crash is caused by the combination of three changes in this PR interacting poorly with the new-account onboarding navigation flow:

  1. enableFreeze(true) (src/setup/index.ts:20) enables react-native-screens freeze globally on mobile, making all non-focused screens eligible for Suspense-based freezing.

  2. The @react-navigation/native-stack patch removes the Fabric-specific isBelowFocused exemption. Previously on Fabric/iOS, the screen directly below the focused one was exempt from freezing — the original code even had a comment: "On Fabric, when screen is frozen, animated and reanimated values are not updated due to component being unmounted." The patch removes this safety net.

  3. New account creation triggers a specific navigation sequence that exposes this:

    • User creates account → AuthScreens mounts with initial state [HOME] (HOME is focused, not frozen)
    • OpenApp API response loads NVP_ONBOARDINGisOnboardingCompleted transitions from true to false
    • AuthScreens conditionally adds ONBOARDING_MODAL_NAVIGATOR (AuthScreens.tsx:359)
    • OnboardingGuard (OnboardingGuard.ts:217) performs CommonActions.reset() creating state [HOME, ONBOARDING_MODAL_NAVIGATOR]
    • HOME is now non-focused → shouldFreeze=true kicks in
    • After 400ms delay, react-freeze's Suspender throws a Promise (react-freeze/src/index.tsx:20), which unmounts HOME's entire native subtree via React Suspense
    • The UINavigationController (RNSStackController.swift:43) may still be transitioning with setViewControllers(activeControllers, animated: true), encountering an inconsistent native view hierarchy → crash

Why this is a new regression (not seen in v1 PR #82764)

All v1 issues (#85184, #85185, #85149, #85170, #85250) were freezes/unresponsiveness, not actual crashes. The new account creation flow was never a known failure mode. The v2 fixes (400ms delay, modal checks, freeze defer) changed the timing characteristics enough to turn what was previously a freeze-class issue into a native crash during the specific onboarding navigation sequence.

Notably, VickyStash also observed an onboarding issue for Gmail users on this PR branch (comment from 2026-03-14), though it was attributed to main. situchan's crash may be related or could be a distinct failure in the same navigation flow.

Evidence Chain

Step What happens Where
Auth completes AuthScreens mounts, HOME is focused AuthScreens.tsx
OpenApp loads onboarding data isOnboardingCompletedfalse Onboarding.ts:12-16
Guard redirects reset()[HOME, ONBOARDING_MODAL_NAVIGATOR] OnboardingGuard.ts:217, getAdaptedStateFromPath.ts:317
HOME loses focus shouldFreeze = !isPreloaded && !isFocusedtrue native-stack patch
400ms + rAF later Suspense unmounts HOME's native children DelayedFreeze patch, react-freeze/src/index.tsx:20
Native conflict UINavigationController encounters empty/inconsistent view RNSStackController.swift:43

Suggestions

  1. Quick fix: Exempt the onboarding flow from freeze — e.g., don't freeze HOME when ONBOARDING_MODAL_NAVIGATOR is the focused screen.
  2. Safer fix: Restore the isBelowFocused exemption on Fabric for native-stack screens, since the original comment explains exactly why it was needed. The ScreenFreezeWrapper approach (web-only) doesn't have this issue because web doesn't use native UINavigationController animations.
  3. Diagnostic: Getting the native crash stack trace from Xcode (EXC_BAD_ACCESS, RCTAssert, etc.) would confirm the exact native component that fails and help determine the best fix.

Open Questions

  • Does the crash also happen on Android, or is it iOS-only? If iOS-only, it strongly confirms the Fabric isBelowFocused exemption removal as the root cause.
  • Would increasing FREEZE_DELAY_MS (e.g., to 1000ms) prevent the crash? If so, it's a timing issue where 400ms isn't enough for the onboarding reset animation to complete.
  • Is the crash deterministic or timing-dependent (race condition)?

@VickyStash
Copy link
Contributor Author

Yeah, I'm able to reproduce that + overall the behaviour on ios became super weird (strange navigation transitions and etc). I'm trying to see what has happend, maybe some overlapping updates were merged.

@VickyStash
Copy link
Contributor Author

VickyStash commented Mar 23, 2026

Okay, it's seems to be broken after React Native v0.83 upgrade merge. I'm figuring out why

@VickyStash
Copy link
Contributor Author

VickyStash commented Mar 23, 2026

Okay, it looks like the Suspense mechanism is starting to behave differently in React Native v0.83 (React 19.2). And it's really messing up the navigation on the native app.

But there is a new component supported in React 19.2 - Activity - it hides components and unmounts effects. I had a quick test, and it looks pretty good. So maybe it can be a good alternative to the current approach.
UPD: even with using Activity I've started to see weird navigation behaviour on ios (back swiping and navigation animations are broken), so I need to dig into it
UPD: There is no unexpected navigation behaviour if I apply Activity right in the E/App and don't use DelayedFreeze component from react-native-screens. My guess is that the issues are coming from some UI workarounds that react-native-screens has to correct swiping back. Before it helped to fix the issues, right now it seems to break it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants