Repository navigation
Guard DeepLinkHandler against stale post-sign-out initial URL - #92839
carlosmiceli merged 8 commits into
Conversation
On web, react-native-web caches Linking.getInitialURL() at JS bundle load, so after sign-out the cached URL still returns the previous session's path. The DeepLinkHandler effect re-runs on session metadata change and would then call openReportFromDeepLink() with that stale URL, queueing a waitForUserSignIn() callback that fires on the next sign-in and navigates the new account to a route it has no access to. Bail out of the post-sign-out re-run when an initial URL has already been processed once, leaving the first-run signed-out deep-link flow intact.
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.
|
|
I just realized our PR might fail in the case where a user is not logged in but accesses a workspace rule via a deep link. I think we need a more comprehensive guard. I have an idea to add a guard in the patch.diffdiff --git a/src/libs/actions/Link.ts b/src/libs/actions/Link.ts
index f777337f5f9..f9e52f9e539 100644
--- a/src/libs/actions/Link.ts
+++ b/src/libs/actions/Link.ts
@@ -295,6 +295,7 @@ function openReportFromDeepLink(
// Navigate to the report after sign-in/sign-up.
InteractionManager.runAfterInteractions(() => {
waitForUserSignIn().then(() => {
+ let prevHasCompletedGuidedSetupFlow: boolean | undefined;
// Subscribe to onboarding data using connectWithoutView to determine if user has completed the onboarding flow without affecting UI
const connection = Onyx.connectWithoutView({
key: ONYXKEYS.NVP_ONBOARDING,
@@ -303,6 +304,10 @@ function openReportFromDeepLink(
return;
}
+ if (!isAuthenticated && prevHasCompletedGuidedSetupFlow === undefined && val && !isAnonymousUser()) {
+ prevHasCompletedGuidedSetupFlow = val.hasCompletedGuidedSetupFlow;
+ }
+
Navigation.waitForProtectedRoutes().then(() => {
if (route && isAnonymousUser() && !canAnonymousUserAccessRoute(route)) {
signOutAndRedirectToSignIn(true);
@@ -337,6 +342,10 @@ function openReportFromDeepLink(
return;
}
+ if (prevHasCompletedGuidedSetupFlow === false) {
+ return;
+ }
+
// Navigation for signed users is handled by react-navigation.
if (isAuthenticated) {
return;
However, I'm not fully confident this won't introduce regressions. If you go with this diff, please carefully review the impact across all platforms and verify the behavior end-to-end. If you have a better approach, feel free to post it here. |
|
@MobileMage Do you have an ETA for this? |
|
@dmkt9 Yup, the I added the guard in The guard stays narrow, so it won't drop a link the user can reach. Accounts that already onboarded ( Tested on web:
Pushed in |
# Conflicts: # src/libs/actions/Link.ts
|
@MobileMage Thanks. Looking at this |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8511f6d215
ℹ️ 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".
| if (initialHasCompletedGuidedSetupFlow === false) { | ||
| return; |
There was a problem hiding this comment.
Keep pending deep links after onboarding
When a real signed-out user opens a protected deep link and then signs up, the first NVP_ONBOARDING value after sign-in is normally {hasCompletedGuidedSetupFlow: false}, so the new capture above leaves initialHasCompletedGuidedSetupFlow set to false. After the user completes onboarding, hasCompletedGuidedSetupFlowSelector(val) allows handleDeeplinkNavigation() to run, but this guard returns after the Onyx subscription has already been disconnected, so the originally requested deep link is permanently dropped. This regresses the legitimate first-time signed-out deep-link flow that the handler previously waited to complete onboarding before navigating.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
After the user completes onboarding, they will be navigated by navigateAfterOnboarding instead
There was a problem hiding this comment.
@MobileMage But I think you should validate all option onboarding to call navigateAfterOnboarding for sure.
| return; | ||
| } | ||
|
|
||
| // Don't honor a deep link captured before the user finished onboarding (#91437). |
There was a problem hiding this comment.
| // Don't honor a deep link captured before the user finished onboarding (#91437). | |
| // Don't honor a deep link captured when the user has to complete onboarding, since after finishing it the user will be navigated by `navigateAfterOnboarding```` |
| if (initialHasCompletedGuidedSetupFlow === false) { | ||
| return; |
There was a problem hiding this comment.
After the user completes onboarding, they will be navigated by navigateAfterOnboarding instead
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8511f6d215
ℹ️ 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".
| if (initialHasCompletedGuidedSetupFlow === false) { | ||
| return; |
There was a problem hiding this comment.
Preserve legitimate signed-out deep links after onboarding
When a user opens a real report/workspace/invite deep link while signed out and then completes onboarding, the onboarding subscription first observes hasCompletedGuidedSetupFlow: false and this new guard later returns before navigateHandler can open the requested route. That suppresses not only the stale post-sign-out URL from #91437 but also valid first-time signup deep links, so new users can be dropped on the default post-onboarding destination instead of the link they opened. The stale URL case needs to be distinguished before queuing the callback rather than treating every pre-onboarding deep link as stale.
Useful? React with 👍 / 👎.
| // Drop a non-report deep link captured before the user finished onboarding (#91437). | ||
| // Scope this to routes without a reportID: a report deep link self-heals in navigateHandler | ||
| // below (it falls back to the last accessed report/Concierge when the report isn't | ||
| // accessible), so dropping those would lose a legitimate first-time sign-up link (e.g. an |
There was a problem hiding this comment.
I don't follow this. Why does a user who needs to complete onboarding need to navigate to the last accessed report? If the user is new, wouldn't the last accessed report also be empty?
Additionally, is the deep link actually processed in this case?
There was a problem hiding this comment.
I've fixed the wordings
There was a problem hiding this comment.
@MobileMage It seems you misunderstood my point. I mean, if the user needs to complete onboarding, they will be navigated by navigateAfterOnboarding, right? And in that case, is this deeplink actually handled? If not handled, adding a check for reportID here doesn't make much sense.
There was a problem hiding this comment.
@dmkt9 Just checked myself. I added some logging and went through the flow. The reportID check was guarding a link that doesn't survive onboarding anyway, and navigateAfterOnboarding replaces it. I've dropped the check and gone back to skipping the deep link outright.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid.hybrid.mp4Android: mWeb Chromeandroid.chrome.mp4iOS: HybridAppios.native.mp4iOS: mWeb Safariios.safari.mp4MacOS: Chrome / Safarimac.safari.mp4 |
|
@MobileMage Sorry for the delay. Could you merge the latest |
|
@dmkt9 Done |
|
🚧 carlosmiceli 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/carlosmiceli in version: 9.4.20-0 🚀
|
|
🤖 Help site review: no changes required. I reviewed the changes in this PR against the help site files under Why: This is an internal bug fix for a transient UI flash — after sign-out → sign-in → onboarding, the "Hmm... it's not here" page briefly flashed because
A search of If you believe a specific article should be updated, reply with the article and the behavior to document and I'll take another pass. |
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.4.20-1 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
On web (and other react-native-web targets), after a user signs out while sitting on a workspace settings path (e.g.
/workspace/{OLD_POLICY_ID}/rules) and then signs in with a new account that completes onboarding, the "Hmm... it's not here" page flashes briefly before the correct post-onboarding screen renders.Root cause:
react-native-webcachesLinking.getInitialURL()at JS bundle load into a module-scoped constant (var initialURL = canUseDOM ? window.location.href : ''). After sign-out, that cached URL still points at the previous session's path.DeepLinkHandler's effect re-runs on session metadata change and on that run callsopenReportFromDeepLink(staleUrl, isAuthenticated=false, ...).openReportFromDeepLinkcaptures the URL and the (false) auth flag in closure and queues anOnyx.connectWithoutViewsubscription viawaitForUserSignIn().then(...). On the next sign-in,NVP_ONBOARDINGupdates, the subscription's callback runs, theif (isAuthenticated) return;bail atLink.ts:341does not trip because the closure capturedfalse, andNavigation.navigate(staleWorkspaceURL)fires — mountingWORKSPACE_NAVIGATOR, triggeringAccessOrNotFoundWrapperto renderNotFoundPagefor a workspace the new account cannot access, and a frame later the legit post-onboarding navigate replaces it. That gap is the flash.This PR guards the
DeepLinkHandler.then((url) => ...)callback with an early return when the user is signed out and an initial URL was already processed once. That blocks the post-sign-out re-run from queueing the staleopenReportFromDeepLinkcall, without affecting the legit signed-out-first-time deep-link flow (which still hasinitialUrlProcessed.current === falseon its first run and sets up its subscription as before).Fixed Issues
$ #91437
PROPOSAL: #91437 (comment)
Tests
Offline tests
Same as Tests above with the network disabled before step 9, then re-enable the network and verify the Not here page does not appear after completing onboarding.
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, 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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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
91437-android-native.mp4
Android: mWeb Chrome
iOS: Native
91437-ios-native.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
Kapture.2026-06-05.at.22.03.13.mp4