Repository navigation
Use PUSH instead of REPLACE for 2FA Download codes navigation on web - #94761
danieldoglas merged 18 commits into
Conversation
|
@parasharrajat 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] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9adf2eecb
ℹ️ 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".
| setCodesAreCopied(); | ||
| announceStatus(translate('fileDownload.success.title')); | ||
| Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.TWO_FACTOR_AUTH_VERIFY.path, backPath), {forceReplace: true}); | ||
| Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.TWO_FACTOR_AUTH_VERIFY.path, backPath), {forceReplace: !isWeb}); |
There was a problem hiding this comment.
Preserve non-settings back paths after success
When this runs on web from a dynamic entry point such as the bank-account 2FA prompt or the required-Xero overlay, using PUSH leaves the recovery-codes screen underneath the later success screen. After the user enables 2FA, browser Back from the success page lands on that root screen; the root page redirects any enabled account to ROUTES.SETTINGS_2FA_ENABLED (lines 73-75), so the user is taken to Settings instead of back to the originating flow. Either keep this intermediate page out of history for non-settings entries or make that enabled-account redirect honor backPath.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Both has a point here. There is bug on web, pressing back button on Success page, shows the recoverycode page which then redirects the user to success page again.
@MobileMage Please do check bot comments.
There was a problem hiding this comment.
That's why I asked you the reason for using Forcereplace on the issue #92564 (comment). It seems this is the bug behind that.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
| const baseState = getStateFromPath(backPath); | ||
| const focusedRoute = baseState ? findFocusedRoute(baseState) : undefined; | ||
| const isSecuritySettingsFlow = focusedRoute?.name === SCREENS.SETTINGS.SECURITY; |
There was a problem hiding this comment.
Switching Download codes to PUSH on web leaves the recovery-codes page in history. After 2FA is enabled, browser Back from the success page re-mounts it, and the existing is2FAEnabled redirect then sends non-settings entries (bank account, Xero) to Settings instead of their originating flow. This makes that redirect honor backPath so those flows return correctly. Happy to pull it into a separate PR if you'd rather keep this one to the single-line change.
|
@MobileMage Can you please merge main? |
|
I think the changes on this PR can cause issues. Testing those. |
Resolve the import-block conflict from main's import reorganization: keep findFocusedRoute/getStateFromPath/SCREENS additions in their new grouped positions. No behavior change.
|
Merging main and fixing my errors |
When Download codes uses PUSH on web, the recovery-codes setup page stays in history under the success page. Pressing browser Back from success re-focused it with 2FA already enabled, and the redirect forwarded the user to the enabled page, looping them straight back to success. useTwoFactorAuthRoute already routes an already-enabled user to the enabled page, so the setup page is only reached this way via back navigation. Go back out of the flow (Navigation.goBack) instead of forwarding, which breaks the loop without the forceReplace lever, and hide the recovery-codes content while 2FA is enabled so it does not flash before the redirect runs.
|
Can you explain your solution? |
|
I figured since |
|
Will this work if we refresh the page. |
|
@MobileMage Can you answer that question? |
|
@parasharrajat apologies for the delay. A hardware failure took out the drive holding my local branch and repository for this PR. I'm rebuilding the environment now and will follow up on your open questions once it's restored. |
|
Let me know once that is done. |
A browser back on a freshly loaded page rebuilds the 2FA right modal, so its beforeRemove listener clears the recovery codes after the setup page has already mounted. The mount effect never saw that because it did not depend on the codes, leaving an empty box with a copy button that copied nothing and no download button. Depend on the codes so the page refetches, and hide the copy button while there is nothing to copy.
|
@parasharrajat Refresh does break it. Reloading and then pressing browser Back lands on the recovery codes page with an empty box, I've fixed it now so the effect now depends on the codes so it refetches, and the copy button is hidden while there is nothing to copy. |
|
@parasharrajat the refresh case is fixed and pushed in 45344cb. Ready for another look when you get a chance. |
|
will check tomorrow. |
|
@parasharrajat both comments are addressed and main is merged. Ready for another look when you have a minute. |
|
I will get this tested next working day. |
|
Gentle bump @parasharrajat |
|
@MelvinBot review this. |
ReviewThe core fix (PUSH on web at DynamicTwoFactorAuthPage.tsx:232) looks right. The new 1. The reload fallback never runs on web (L94-L101) 2. Browser Back from Success before "Got it" still doesn't leave the flow (L73-L77)
I didn't test this end to end. It needs a manual check: enable 2FA from Settings > Security on web, then press browser Back on the Success page. The comment at L70 ("only reachable by navigating back into it, so the effect below leaves the flow") only holds after "Got it". 3. Nit: The tests in |
…navigation on web PUSH put the verify page on top of the recovery-codes page. The app builds a dynamic route URL from the page underneath plus the page's own suffix, so the URL became .../two-factor-auth/two-factor-auth/verify, the success page got the wrong back path, and "Got it" no longer opened the enabled page. Browser Back from the success page also returned to the recovery codes with 2FA already on. Go back to REPLACE on every platform, which keeps the stack flat as on main, and remove the redirect handling that PUSH needed. To still avoid the original bug, start the download after the navigation on web, so the save dialog cannot open while the history.go(-1) of the REPLACE is pending.
…ter the navigation on web" This reverts commit e39b52a.
…lat under PUSH With PUSH on web the recovery-codes page stays under the verify and success pages. - Browser Back from the success or enabled page returned to the recovery codes with 2FA already on. A page that was open before 2FA got enabled now goes back once more, so Back leaves the flow as it does on main. - The canGoBack fallback never ran, because a reload of this URL does not mount the page. A fresh mount with 2FA on opens the enabled page again, as on main. - The redirect to the success page is removed. It made the page bounce. - The hidden page no longer reacts when the forced-onboarding handoff resets the account data. It used to replace the success page with the verify-account page. - getPathFromState added the suffix of the page underneath a second time, which gave /two-factor-auth/two-factor-auth/verify. The success page then got the wrong back path and "Got it" did not open the enabled page. A dynamic route that extends the suffix of the route underneath no longer repeats it. Tests now follow Given / When / Then.
|
@parasharrajat the PR is back on the PUSH approach. Review points fixed: browser Back from success or enabled leaves the flow, the |
|
Gentle bump @parasharrajat |
…tead of changing getPathFromState The getPathFromState change also flattened the URLs of other flows that stack a dynamic route on the route it extends. The merge-transaction flow does that on purpose (merge/:transactionID/receipt on top of merge/:transactionID), and it lost the list step on a reload. getPathFromState is back to main's version. With PUSH on web, the recovery codes page stays under the verify page. Once 2FA is on, it now removes itself from the 2FA stack. The stack is then the same as on native, where the verify page replaced it, so the success page gets its back and forward paths from the plain URL, "Got it" opens the enabled page again, and browser Back from the success or enabled page leaves the flow.
…'s behaviour on top - The page removes itself only when another page of the 2FA stack is above it. A reset to an empty stack is not valid, so a covered page alone in its stack now does nothing. - On top with 2FA on and no setup in progress, the page opens the enabled page again, as on main. That keeps native and stale local data unchanged. - On top with 2FA on and the setup in progress, it leaves the flow instead of showing an empty page. - Tests: remove an unused @ts-expect-error that failed the typecheck job, wrap Onyx updates in act(), and cover the new cases.
|
@MobileMage, can you resolve conflicts? I will wrap this one first. |
|
Yeah, resolving now |
…d-codes-web-back # Conflicts: # src/pages/settings/Security/TwoFactorAuth/DynamicTwoFactorAuthPage.tsx # tests/ui/DynamicTwoFactorAuthPageTest.tsx
|
@parasharrajat conflicts resolved, ready for review. |
|
@MelvinBot review this PR. Give me a summary of changes done over time on this PR. |
ReviewReviewed head The final approach is:
See the navigation and enabled-state handling and Download handler. How the PR evolved
Current scope: only the 2FA setup page and its UI test. There is no remaining shared navigation-serializer change, and deferred downloading is not the final implementation. Validation and remaining coverage
|
parasharrajat
left a comment
There was a problem hiding this comment.
Reviewer Checklist
- I have verified the author checklist is complete (all boxes are checked off).
- I verified the correct issue is linked in the
### Fixed Issuessection above - I verified testing steps are clear and they cover the changes made in this PR
- I verified the steps for local testing are in the
Testssection - I verified the steps for Staging and/or Production testing are in the
QA stepssection - I verified the steps cover any possible 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 verified the steps for local testing are in the
- I checked that screenshots or videos are included for tests on all platforms
- I included screenshots or videos for tests on all platforms
- I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
- I verified tests pass on all platforms & I tested again on:
- Android: HybridApp
- Android: mWeb Chrome
- iOS: HybridApp
- iOS: mWeb Safari
- MacOS: Chrome / Safari
- If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- I verified proper code patterns were followed (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.
toggleReportand notonIconClick). - 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 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 that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
- If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- I verified that this PR follows the guidelines as stated in the Review Guidelines
- I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarhave been tested & I retested again) - If a new component is created I verified that:
- A similar component doesn't exist in the codebase
- All props are defined accurately and each prop has a
/** comment above it */ - The file is named correctly
- The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- The only data being stored in the state is data necessary for rendering and nothing else
- For Class Components, any internal methods passed to components event handlers are bound to
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - All JSX used for rendering exists in the render method
- The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- 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 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
Avataris modified, I verified thatAvataris 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
Designlabel and/or tagged@Expensify/designso the design team can review the changes.
- For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
- If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Screenshots
🔲 iOS / native
08.11.2026_20.36.10_REC.mp4
🔲 iOS / Safari
08.11.2026_20.38.28_REC.mp4
🔲 MacOS / Chrome
08.11.2026_19.53.57_REC.mp4
🔲 Android / native
08.11.2026_20.24.18_REC.mp4
🎀 👀 🎀 C+ reviewed
|
🚧 danieldoglas has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/danieldoglas in version: 9.5.37-0 🚀
|
|
No help site update needed — this PR fixes navigation and recovery-code handling during existing 2FA setup, restoring expected behavior without adding a feature or making an existing article sentence incorrect. |
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.5.37-1 🚀
Bundle Size Analysis (Sentry): |

Explanation of Change
On web, the Download codes button on the 2FA recovery-codes step navigated to the Verify step with
forceReplace: true(a REPLACE action). On macOS Chrome, the native "Save As" dialog blurs the tab and delays thepopstateevent past React Navigation's 100 mshistory.go(-1)safety window. The delayedpopstateis then treated as a user-initiated back press, souseLinkingmatches the cached pre-2FA/settings/securitystate and callsresetRoot, which unmounts the 2FA RHP and clears the recovery codes, so the page "closes" instead of advancing to the Verify/QR step.The fix changes the navigation to
forceReplace: !isWeb:createMemoryHistory.go(-1)vspopstaterace can never occur, and the browser Back button correctly returns from Verify to the Recovery-codes step.forceReplace: true), preserving the back-stack behavior fixed in [BT-128] Migrate forwardTo Routes - 2FA Flow #89608.Fixed Issues
$ #92564
PROPOSAL: #92564 (comment)
Tests
Offline tests
Same as Tests. Generating recovery codes needs a server response, so there is no offline-specific behavior.
QA Steps
Same as Tests, on staging.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Kapture.2026-06-27.at.06.16.49.mp4
Android: mWeb Chrome
Cap.2026-08-18.at.03.23.34.mp4
iOS: Native
Kapture.2026-06-26.at.20.36.12.mp4
iOS: mWeb Safari
Cap.2026-08-18.at.02.25.25.mp4
MacOS: Chrome / Safari
Kapture.2026-06-25.at.16.32.55.mp4