[No QA] [Performance] Add pre-mount destination hook and usage guard
Explanation of Change
Adds usePreMountDestination to centralize narrow-layout destination pre-insert/reveal behavior under RHP. It schedules pre-insert work during idle time after the RHP transition, handles cleanup/reveal fallbacks, and adds ESLint enforcement, AI reviewer guidance, and unit coverage.
Fixed Issues
$ https://github.com/Expensify/App/issues/94673 PROPOSAL: N/A
Tests
N/A. This PR adds reusable hook and enforcement infrastructure but does not migrate any user-facing flow. Validation is covered by CI unit tests, lint, and typecheck.
Offline tests
N/A
QA Steps
N/A. This PR only adds shared hook infrastructure and does not migrate any user-facing flow.
PR Author Checklist
- [x] I linked the correct issue in the
### Fixed Issuessection above - [x] I wrote clear testing steps that cover the changes made in this PR
- [x] I added steps for local testing in the
Testssection - [x] I added steps for the expected offline behavior in the
Offline stepssection - [x] I added steps for Staging and/or Production testing in the
QA stepssection - [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- [x] 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)
- [x] 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).
- [x] I added steps for local testing in the
- [x] I included screenshots or videos for tests on all platforms
- [x] I ran the tests on all platforms & verified they passed on:
- [x] Android: Native
- [x] Android: mWeb Chrome
- [x] iOS: Native
- [x] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [x] 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)
- [x] I followed proper code patterns (see Reviewing the code)
- [x] 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) - [x] I verified that comments were added to code that is not self explanatory
- [x] 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.
- [x] 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)
- [x] 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.
- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [x] I followed the guidelines as stated in the Review Guidelines
- [x] 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 usingAvatarare working as expected) - [x] If any new file was added I verified that:
- [x] 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
- [x] If a new CSS style is added I verified that:
- [x] A similar style doesn't already exist
- [x] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
- [x] If new assets were added or existing ones were modified, I verified that:
- [x] The assets are optimized and compressed (for SVG files, run
npm run compress-svg) - [x] The assets load correctly across all supported platforms.
- [x] The assets are optimized and compressed (for SVG files, run
- [x] 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.
- [x] 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) - [x] 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.
- [x] 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.
- [x] 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:
- [x] I verified that all the inputs inside a form are aligned with each other.
- [x] I added
Designlabel and/or tagged@Expensify/designso the design team can review the changes.
- [x] I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
- [x] If the
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
:warning: 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. :warning:
Codecov Report
✅ Changes either increased or maintained existing code coverage, great job!
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/CONST/index.ts | 94.81% <ø> (ø) |
|
| src/libs/Navigation/TransitionTracker.ts | 100.00% <100.00%> (ø) |
|
| src/libs/Scheduler/index.ts | 95.65% <95.65%> (ø) |
|
| src/hooks/usePreMountDestination/index.ts | 94.59% <94.59%> (ø) |
|
| ... and 116 files with indirect coverage changes |
@codex review
@codex review 🙏
@codex review
@codex review
Codex Review: Didn't find any major issues. Another round soon, please!
Reviewed commit: ca20fb4e85
ℹ️ 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".
@eVoloshchak 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]
@MelvinBot review
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.
🤖 Review — infrastructure-only PR (new usePreMountDestination hook + ESLint guard + PERF-17 rule + unit tests). No user-facing flow is migrated. Overall this looks solid and well-tested; the two @codex/AI findings already fixed (narrow-layout gating, preserve-callback capture, CONSISTENCY-3) were the right calls. A few notes, none blocking:
1. Duplicate cleanup logic (CONSISTENCY-3, again). The pre-insert effect's cleanup at usePreMountDestination/index.ts:128-135 is byte-identical to cancelPreInsert(). This is the same duplication that was flagged and fixed for the unmount effect — the cleanup here can just return cancelPreInsert; (or return () => cancelPreInsert();) so the cancel sequence lives in one place.
2. scheduler as a direct dependency. Pinning [email protected] matches what React 19.2.0 already ships, and the lockfile dedupes to a single node_modules/scheduler, so there's no second-copy / split-task-queue risk today. Just flagging the coupling: on a future React bump this exact pin must move in lockstep, otherwise npm could resolve a second scheduler copy and the idle queue would no longer be shared with React's. Using the unstable_* API from the standalone package is a supported pattern, so no objection — just worth a comment near the pin or the shim noting it must track React's scheduler.
3. Enforcement ships ahead of adoption. The hook has zero call sites and the new no-direct-pre-insert-fullscreen-under-rhp rule errors on direct preInsertFullscreenUnderRHP usage, grandfathering the two current callers (IOURequestStepConfirmation.tsx and useSkipConfirmationPreInsert.ts) via a hardcoded path allowlist. Both existing callers are correctly covered. This is a reasonable staged rollout, but note the timing-parity assumptions (the preInsertTiming: 300 legacy branch, the 500ms open-transition wait, reveal-vs-dismiss orchestration) are only exercised against mocks in the unit tests — they won't be validated against a real RHP flow until a follow-up migrates one. Worth keeping the first migration PR small so any drift surfaces early.
Correctness spot-checks (all pass)
- Reveal when pre-insert is still pending:
reveal()callscancelPreInsert()first;preInsertedRouteRefis only set after a successful insert, so a pending-but-not-run task falls through torevealRouteBeforeDismissingModal(route)— no double-insert, no gap. ✔ - Reveal when another flow owns the global flag:
preInsertedRouteRef.current === routeguard fails, so it falls back to reveal without clearing the other flow's flag. Covered by the "another flow owns the global pre-insert flag" test. ✔ - Route change A→B: the
[route]cleanup effect removes the pre-inserted route A (unless revealed/preserved) before B's effects run; the preserve callback is read from the correct route thanks to the passive ref-update effect. ✔ shouldIgnoreLayoutbypass correctly gates ongetIsNarrowLayout()captured at flow start rather than the RHP-awareshouldUseNarrowLayout, per the earlier fix. ✔
Nothing here blocks merge — item 1 is a quick cleanup, items 2–3 are context for reviewers. 👍
To use Codex here, create a Codex account and connect to github.
:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! :test_tube::test_tube: Built from App PR Expensify/App#95397.
| Android :robot: | iOS :apple: |
|---|---|
| https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-android-Adhoc-10ec3840c10-163e75a-09c9c5b4ef34a5e22121d06788e6c9a4035d3ec2/index.html | https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-ios-device-AdHoc-10ec384-163e75a-13b87723a63404f874decf6c092a99976786c786/index.html |
| Web :spider_web: |
|---|
| https://95397.pr-testing.expensify.com |
:eyes: View the workflow run that generated this build :eyes:
Addressed Melvin feedback, deduped the second cleanup by returning cancelPreInsert directly and added a note that the direct scheduler dependency should stay aligned with React/React Native.
Reviewer Checklist
- [x] I have verified the author checklist is complete (all boxes are checked off).
- [x] I verified the correct issue is linked in the
### Fixed Issuessection above - [x] I verified testing steps are clear and they cover the changes made in this PR
- [x] I verified the steps for local testing are in the
Testssection - [x] I verified the steps for Staging and/or Production testing are in the
QA stepssection - [x] 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)
- [x] 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)
- [x] I verified the steps for local testing are in the
- [x] I checked that screenshots or videos are included for tests on all platforms
- [x] I included screenshots or videos for tests on all platforms
- [x] 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.
- [x] I verified tests pass on all platforms & I tested again on:
- [x] Android: HybridApp
- [x] Android: mWeb Chrome
- [x] iOS: HybridApp
- [x] iOS: mWeb Safari
- [x] MacOS: Chrome / Safari
- [x] 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
- [x] I verified proper code patterns were followed (see Reviewing the code)
- [x] 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). - [x] I verified that comments were added to code that is not self explanatory
- [x] 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.
- [x] 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)
- [x] 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.
- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
- [x] 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) - [x] If a new component is created I verified that:
- [x] A similar component doesn't exist in the codebase
- [x] All props are defined accurately and each prop has a
/** comment above it */ - [x] The file is named correctly
- [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- [x] The only data being stored in the state is data necessary for rendering and nothing else
- [x] 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) - [x] 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) - [x] All JSX used for rendering exists in the render method
- [x] 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
- [x] If any new file was added I verified that:
- [x] 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
- [x] If a new CSS style is added I verified that:
- [x] A similar style doesn't already exist
- [x] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
- [x] 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.
- [x] 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) - [x] 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.
- [x] 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.
- [x] 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:
- [x] I verified that all the inputs inside a form are aligned with each other.
- [x] I added
Designlabel and/or tagged@Expensify/designso the design team can review the changes.
- [x] For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
- [x] If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Screenshots/Videos
Android: HybridApp
https://github.com/user-attachments/assets/1af1418c-b076-4427-a92d-56c608864763
Android: mWeb Chrome
https://github.com/user-attachments/assets/57ba5ef0-b619-499b-9fb1-c882ecabbc88
iOS: HybridApp
https://github.com/user-attachments/assets/fd11c0ba-b165-4e50-b0f3-49e6431036b9
iOS: mWeb Safari
https://github.com/user-attachments/assets/05e16be1-0584-4e74-be6c-797984f6108e
MacOS: Chrome / Safari
https://github.com/user-attachments/assets/0ac74d67-f4fd-40e5-83b4-38e1fdf3a2fe
(I have an ongoing review that I need to circle back and finish later, please hold off on merging)
Yep not merging! all yours
🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.
:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! :test_tube::test_tube: Built from App PR Expensify/App#95397.
| Android :robot: | iOS :apple: |
|---|---|
| https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-android-Adhoc-ae923f02f5a-3fececf-6ff2b185419724121f2ce8c86f3cf57f121f1305/index.html | https://ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com/rock-artifacts/ad-hoc/rock-ios-device-AdHoc-ae923f0-3fececf-75f424ee4d07b22001244ade8cf51b4a1d308e32/index.html |
| Web :spider_web: |
|---|
| https://95397.pr-testing.expensify.com |
:eyes: View the workflow run that generated this build :eyes:
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.4.34-0 🚀
| platform | result |
|---|---|
| 🕸 web 🕸 | success ✅ |
| 🤖 android 🤖 | success ✅ |
| 🍎 iOS 🍎 | success ✅ |