Skip to content

Upgrade react-navigation to latest#85743

Open
WojtekBoman wants to merge 8 commits intoExpensify:mainfrom
software-mansion-labs:react-navi-packages-bump
Open

Upgrade react-navigation to latest#85743
WojtekBoman wants to merge 8 commits intoExpensify:mainfrom
software-mansion-labs:react-navi-packages-bump

Conversation

@WojtekBoman
Copy link
Contributor

@WojtekBoman WojtekBoman commented Mar 19, 2026

Explanation of Change

This PR upgrades the react-navigation packages to the latest versions, which were previously reverted from staging (#78443) due to several deploy blockers caused by focus and navigation regressions. Those regressions have now been identified and fixed, allowing the upgrade to land cleanly.
Package version changes:

Package Old New
@react-navigation/core (not pinned) 7.16.1
@react-navigation/native 7.1.10 7.1.33
@react-navigation/native-stack 7.3.14 7.14.5
@react-navigation/stack 7.3.3 7.8.5
@react-navigation/material-top-tabs 7.2.13 7.4.19
@react-navigation/devtools ^6.0.10 7.0.52

Why useNavigationState was replaced with useRootNavigationState in 2 files

In newer versions of react-navigation, useNavigationState reads the state from the nearest navigator in the component tree rather than the root navigator. Both SearchContextProvider (in SearchContext.tsx) and RequireTwoFactorAuthenticationOverlay are rendered outside of any navigator, which means useNavigationState no longer has access to a navigation context and throws an error or returns stale/incorrect state.
useRootNavigationState is a custom hook that subscribes directly to navigationRef (the root navigator ref), bypassing the context hierarchy entirely. This makes it safe to call from any component regardless of where it sits in the tree, and ensures both hooks always receive the full, up-to-date root navigation state.

Fixed Issues

$ #75700
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Test steps

  1. Login auto-focus (#78435) – Sign out from new.expensify.com. Verify the email field is auto-focused and no validation error appears underneath it on the sign-in page.
  2. RHP backdrop click after creating expense (#78440) – Create a new expense in a workspace chat (+ → Create expense → Manual → enter amount → Next → Create expense). Immediately click outside the RHP. Verify the app does not navigate back to workspace settings or any other previous page.
  3. RHP flash when editing split expense amount (#78444) – Create an expense, split it, open the detail page of one of the split expenses, tap the amount to edit. Verify the background does not briefly flash the detail page behind the new RHP.
  4. Chat composer focus (#78449) – Open any chat, focus the composer, then navigate to Reports and back to Inbox. Verify the composer is focused. Then switch between two different chats and verify the composer is focused in the destination chat.

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-03-19.at.15.04.50.mov

@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. ⚠️

@WojtekBoman WojtekBoman force-pushed the react-navi-packages-bump branch 3 times, most recently from e8614ab to 093c38c Compare March 19, 2026 11:02
@WojtekBoman WojtekBoman changed the title React navi packages bump Upgrade react-navigation to latest Mar 19, 2026

function SearchContextProvider({children}: SearchContextProps) {
const focusedScreen = useNavigationState((state) => getDeepestFocusedScreen(state));
const focusedScreen = useRootNavigationState((state) => getDeepestFocusedScreen(state));
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this going to trigger rerender every focused screen change?

Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to use much stronger selector for this one e.g. return undefined for screens other thant search root. You have something like that in the code below

function RequireTwoFactorAuthenticationOverlay() {
const shouldShowRequire2FAPage = useShouldShowRequire2FAPage();
const isIn2FASetupFlow = useNavigationState((state) => {
const isIn2FASetupFlow = useRootNavigationState((state) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This one looks safe 👍

@WojtekBoman WojtekBoman force-pushed the react-navi-packages-bump branch from 2c50533 to a3c9875 Compare March 20, 2026 13:56
@WojtekBoman WojtekBoman marked this pull request as ready for review March 20, 2026 14:05
@WojtekBoman WojtekBoman requested review from a team as code owners March 20, 2026 14:05
@melvin-bot melvin-bot bot requested review from aimane-chnaif and trjExpensify and removed request for a team and trjExpensify March 20, 2026 14:05
@melvin-bot
Copy link

melvin-bot bot commented Mar 20, 2026

@aimane-chnaif 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]

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/Search/SearchContext.tsx 42.85% <ø> (+0.82%) ⬆️
...rc/pages/RequireTwoFactorAuthenticationOverlay.tsx 37.03% <ø> (ø)
...on/AppNavigator/Navigators/RightModalNavigator.tsx 5.43% <0.00%> (-0.06%) ⬇️
... and 488 files with indirect coverage changes

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: a3c9875f82

ℹ️ 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 157 to +162
isExecutingRef.current = true;
navigation.goBack();
setTimeout(() => {
isExecutingRef.current = false;
}, CONST.ANIMATED_TRANSITION);
const currentState = navigationRef.getRootState();

// There is a brief moment when the RHP is not in the state anymore but the overlay is still visible (closing RHP animation)
// We need to block overlay press function in such case because it would go back from the currently active full screen.
if (currentState.routes.at(-1)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR) {

Choose a reason for hiding this comment

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

P1 Badge Reset overlay debounce flag when no back navigation occurs

handleOverlayPress now sets isExecutingRef.current = true before checking whether the root route is RIGHT_MODAL_NAVIGATOR, but the flag is only cleared inside that if block. In flows where the overlay press happens while another root route is on top (the exact race this change is guarding against), the function exits with the flag still true, so subsequent backdrop presses in the same mounted RHP instance are ignored and the overlay can appear unresponsive. Please clear the flag in the non-matching branch as well (or use a finally-style reset path).

Useful? React with 👍 / 👎.

@github-actions
Copy link
Contributor

🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@MelvinBot
Copy link
Contributor

🔍 PR Review

Summary: Upgrades @react-navigation packages to latest versions (previously reverted from staging due to regressions). The regressions have been identified and addressed in this PR.

CI Status

All checks pass (ESLint, typecheck, all 8 test shards, perf-tests, validate-patches, etc.).

Source Code Changes

SearchContext.tsx — Replaces useNavigationState with useRootNavigationState. The refactored code is cleaner: instead of extracting focusedScreenName / focusedScreenParams separately and combining in a useMemo, it derives the search params directly inside the selector. The hook stores the selector in a ref to avoid unnecessary re-subscriptions, so this is safe.

RequireTwoFactorAuthenticationOverlay.tsx — Same useNavigationStateuseRootNavigationState swap. Both these components render outside any navigator, so useNavigationState (which reads from the nearest navigator context) breaks in the newer react-navigation versions. useRootNavigationState subscribes directly to navigationRef, which works from anywhere.

RightModalNavigator.tsx — Adds a guard in the overlay press handler: checks if RIGHT_MODAL_NAVIGATOR is still the top route before calling goBack(). This prevents a race condition during the closing animation where the overlay is still visible but the RHP has already been removed from the state — without this check, goBack() would navigate away from whatever screen is now active.

Patches

All existing patches properly re-targeted to new versions. The dontDetachScreen patch accounts for upstream structural changes (class → function component refactor in Card, isScreenActiveactivityState rename, CardContainerCardA11yWrapper). validate-patches check passes, confirming they apply cleanly.

Tests

Test mocks updated to match the new useRootNavigationState API (selector-based). Two additional test files (MoneyRequestReportActionsListRejectModalTest, TransactionGroupListItemTest) add missing mocks for useRootNavigationState and getDeepestFocusedScreen.

Verdict

The code changes look correct and well-motivated. The useRootNavigationState pattern is the right approach for components outside the navigator tree, the RHP race condition fix is sound, and the patches are properly maintained. No concerns from my review.

@aimane-chnaif
Copy link
Contributor

Bug: After following steps in #78456, it lands on Search page. Tested in android adhoc build.
On production, it lands on Subscription settings page.

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: a3c9875f82

ℹ️ 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 +84 to 88
const params = useRootNavigationState((state) => {
const focusedScreen = getDeepestFocusedScreen(state);
if (focusedScreen?.name !== SCREENS.SEARCH.ROOT) {
return undefined;
}

Choose a reason for hiding this comment

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

P1 Badge Read the initial search route before defaulting to empty query

useRootNavigationState initializes with selector(undefined) and only updates on later root state events, so on a cold load or deep link directly into Search the first value here is undefined and there is no initial ready-state update to correct it. That makes definedQueryParam fall back to buildSearchQueryString(), and useSearchPageSetup() then fires search() for the default hash instead of the requested q/rawQuery. In practice, refreshing or opening a saved-search URL will show the wrong search until some later navigation change happens.

Useful? React with 👍 / 👎.

Comment on lines +40 to 42
const isIn2FASetupFlow = useRootNavigationState((state) => {
const focusedScreen = getDeepestFocusedScreen(state);
return isTwoFactorSetupScreen(focusedScreen?.name);

Choose a reason for hiding this comment

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

P1 Badge Read the initial 2FA route before showing the blocking overlay

This has the same initial-state problem: when the app restores directly into a 2FA setup screen, useRootNavigationState returns undefined until some later navigation event, so isIn2FASetupFlow stays false on the initial load. Because useShouldShowRequire2FAPage() is still true during setup, the RequireTwoFactorAuthenticationOverlay renders on top of SETTINGS_2FA_ROOT/SETTINGS_2FA_VERIFY_ACCOUNT and can block the setup flow until the user triggers another navigation change.

Useful? React with 👍 / 👎.

@WojtekBoman WojtekBoman force-pushed the react-navi-packages-bump branch from a3c9875 to 0236ffe Compare March 25, 2026 08:56
@WojtekBoman
Copy link
Contributor Author

Bug: After following steps in #78456, it lands on Search page. Tested in android adhoc build. On production, it lands on Subscription settings page.

I've investigated it and I know what's causing this issue, now I want to check if this issue occurs on main as well. If so, I'll raise a separate PR to fix it!

@WojtekBoman WojtekBoman force-pushed the react-navi-packages-bump branch from 7ddfa70 to cf26342 Compare March 25, 2026 11:54
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