Skip to content

Fix iOS crash when returning from Settings after enabling Contacts access - #97992

Merged
Beamanator merged 3 commits into
mainfrom
claude-deferRouteRestoreOnReload
Aug 7, 2026
Merged

Beamanator merged 3 commits into
mainfrom
claude-deferRouteRestoreOnReload

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

On iOS, tapping Import contacts sends the user to device Settings; when the Contacts permission changes, iOS cold-reloads the app (see goToSettings). On relaunch, Expensify.tsx restores the persisted deep route (lastRoute) — here the money-request participant selector, an RHP route — by calling Navigation.navigate(lastRoute) synchronously inside a useLayoutEffect on the boot frame.

Restoring a deep RHP route on that same frame kicks the @react-navigation/stack card's legacy Animated native-driver entering transition while the tree is still hydrating. When the card unmounts mid-transition, the native animation's .start() → findNodeHandle runs against an already-unmounted node and throws "Unable to find node on an unmounted component", crashing the app. This matches the iOS crash stack reported on the issue (start → __startAnimationIfNative → __makeNative → _connectAnimatedView → findNodeHandle).

The fix defers the route restore by one frame with requestAnimationFrame, so the restore no longer races the card's mount-then-unmount within the boot frame. cancelAnimationFrame is called in the effect cleanup to avoid a stray navigate if the effect re-runs. requestAnimationFrame is used rather than InteractionManager.runAfterInteractions (which is deprecated in our bundled React Native — see #71913) per the approved proposal.

Fixed Issues

$ #97939
PROPOSAL: #97939 (comment)

Tests

Same as QA steps

Offline tests

Same as QA steps

QA Steps

  1. Launch the hybrid Expensify app.
  2. Log in with valid credentials.
  3. Press the "+" button.
  4. Select "Create expense".
  5. Navigate to the Create Expense page.
  6. Take a photo of an expense.
  7. When the soft permission modal to import contacts appears (first time only), tap "Continue".
  8. Deny access to device contacts in the native permission dialog.
  9. In the recipient list, perform a search that returns no results.
  10. When the "Import contacts" clickable text appears, tap it
  11. After app navigates to the native device Settings > Enable Contacts access for Expensify.
  12. Return to the Expensify app.
  13. Verify that the app should resume normally, display the Start Chat flow, and show the native device contact list in Expensify.

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 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)
  • 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)
  • 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.
  • 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

…n crash

Co-authored-by: dmkt9 <dmkt9@users.noreply.github.com>
Co-authored-by: dmkt9 <dmkt9@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

The failing checks were not caused by this PR's code — they were a transient GitHub Actions infrastructure outage. I re-triggered CI with an empty commit.

What failed: spellcheck, typecheck, and test (job 6) all died at GitHub's Getting action download info step (before running any code) with Bad Gateway / Service Unavailable / Internal Server Error during a ~15:22–15:28 UTC window on 2026-08-06. GitHub couldn't resolve action downloads (e.g. actions/cache, useblacksmith/checkout) and gave up after retries. The sibling test jobs (1–5, 7, 8), Bun tests, ESLint, Oxfmt, and the builds all passed on the same commit — a classic partial-outage signature, not a code problem.

Evidence
spellcheck  Set up job  Failed to resolve action download info. Error: Bad Gateway
spellcheck  Set up job  Internal Server Error occurred while resolving "actions/cache@9255dc7..."
                        Internal Server Error occurred while resolving "useblacksmith/checkout@1c9394c..."
typecheck   Run setupNode  ##[error]Service Unavailable / Failed to resolve action download info.
test (job 6) Set up job    ##[error]Service Unavailable / Failed to resolve action download info.

The only remaining reds — Check independent approval and PR Author Checklist / checklist — are the expected human/approval gates, not test failures.

The re-run is in progress on 8405346. These should now pass on their own — no code change was needed.

@codecov

codecov Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

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/Expensify.tsx 85.83% <0.00%> (-1.46%) ⬇️
... and 362 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

✅ All the code checks are green now. The failures were a transient GitHub Actions outage, not a problem with this PR — the earlier re-trigger fixed them.

On the latest commit, spellcheck, typecheck, and test (job 6) (the three that had failed) all pass, along with every other test job, ESLint, Oxfmt, Bun tests, and the perf tests.

The only two remaining red checks are Check independent approval and PR Author Checklist / checklist — those are the expected human/approval gates that get satisfied through review, not automated failures. No code change was needed.

@dmkt9

dmkt9 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot update your checklist:

  1. Check all checkboxes
  2. Update Tests and Offline tests section to Same as QA steps
  3. Update QA steps section to:
1. Launch the hybrid Expensify app.
2. Log in with valid credentials.
3. Press the "+" button.
4. Select "Create expense".
5. Navigate to the Create Expense page.
6. Take a photo of an expense.
7. When the soft permission modal to import contacts appears (first time only), tap "Continue".
8. Deny access to device contacts in the native permission dialog.
9. In the recipient list, perform a search that returns no results.
10. When the "Import contacts" clickable text appears, tap it
11. After app navigates to the native device Settings > Enable Contacts access for Expensify.
12. Return to the Expensify app.
13. Verify that the app should resume normally, display the Start Chat flow, and show the native device contact list in Expensify.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Updated the checklist as requested:

  • ✅ Checked all checkboxes (Tests, Offline tests, QA steps, and the full PR Author Checklist).
  • ✅ Set the Tests and Offline tests sections to Same as QA steps.
  • ✅ Replaced the QA Steps section with your 13-step flow.

@dmkt9

dmkt9 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot mark this PR as ready

@MelvinBot
MelvinBot marked this pull request as ready for review August 7, 2026 03:20
@MelvinBot
MelvinBot requested a review from a team as a code owner August 7, 2026 03:20
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done — marked this PR as ready for review. ✅

@melvin-bot
melvin-bot Bot requested a review from dmkt9 August 7, 2026 03:20
@melvin-bot

melvin-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

@dmkt9 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 August 7, 2026 03:20
@dmkt9

dmkt9 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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 Issues section 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 Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • 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 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 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)
  • 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 using Avatar have 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
    • 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
    • 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 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 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.
  • 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android.hybrid.mp4
Android: mWeb Chrome
iOS: HybridApp
ios.hybrid.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari

@dmkt9 dmkt9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@melvin-bot
melvin-bot Bot requested a review from Beamanator August 7, 2026 03:23
@MelvinBot

Copy link
Copy Markdown
Contributor Author

The only failing check is Check independent approval, which isn't a code failure and can't be fixed by a push.

Every real CI check is green — Bun tests, ESLint, typecheck, Oxfmt, Storybook tests, test (jobs 1–8), React Compiler Compliance, check, validate, etc. all pass.

Check independent approval stays red until the PR gets an approving review from an independent reviewer (someone other than the author). It's a process gate, not a bug in the diff, so there's nothing for me to change in the code.

Next step: get an independent reviewer to approve the PR and this check will clear on its own.

Comment thread src/Expensify.tsx
}
updateLastRoute('');
Navigation.navigate(lastRoute as Route);
// On iOS, changing the Contacts permission in Settings forces the app to reload (see `goToSettings`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// On iOS, changing the Contacts permission in Settings forces the app to reload (see `goToSettings`).
// On iOS, changing the Contacts permission in Settings forces the app to reload (see `goToSettings`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot handle the comment above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied Beamanator's suggestion — added a blank line to separate updateLastRoute('') from the comment block. Pushed in 2f1f27e.

@joekaufmanexpensify joekaufmanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good for product.

@MelvinBot
MelvinBot requested a review from a team as a code owner August 7, 2026 16:07
@melvin-bot
melvin-bot Bot requested review from dmkt9 and removed request for a team August 7, 2026 16:07
@melvin-bot

melvin-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

@dmkt9 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 a review from Beamanator August 7, 2026 16:09
@MelvinBot

Copy link
Copy Markdown
Contributor Author

The only failing check on this PR is Check independent approval — everything else is passing or still running on the latest commit.

That check isn't a code failure I can fix by pushing a commit. It's a governance gate: it fails until the PR receives an independent approval from a reviewer who isn't the author. There's no code change that clears it.

To resolve: get an independent reviewer to approve the PR (the assigned reviewer / a Contributor+), and the check will pass.

If you're seeing a different check fail, note the latest CI run was still in progress when I looked — re-tag me once it settles and I'll dig into any real failures.

@dmkt9

dmkt9 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@Beamanator All yours

@Beamanator
Beamanator merged commit 36b95af into main Aug 7, 2026
61 of 81 checks passed
@Beamanator
Beamanator deleted the claude-deferRouteRestoreOnReload branch August 7, 2026 17:44
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/Beamanator in version: 9.4.52-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 cancelled 🔪

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 No help site changes required.

I reviewed the change in this PR. It's a purely internal crash fix — src/Expensify.tsx now defers the persisted-route restore by one animation frame (requestAnimationFrame) so the react-navigation card isn't mounted-then-unmounted mid-animation on the iOS boot frame after returning from Settings.

There is no user-facing change here:

  • No new or changed feature, setting, tab, label, or button.
  • No change to any documented workflow — the intended "Import contacts → return to app → resume normally" flow is exactly what the docs would already describe; this just stops it from crashing.
  • No article under App/docs/articles references this behavior (no "Import contacts" content exists there).

Because nothing customer-facing changed, no help site article needs updating, so I did not create a docs PR.

@dmkt9, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.52-11 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

5 participants