Skip to content

Fix infinite loading page after unlinking secondary login from email - #97803

Open
ahmdshrif wants to merge 8 commits into
Expensify:mainfrom
ahmdshrif:sherif/issue-96073-proposal-71631c
Open

Fix infinite loading page after unlinking secondary login from email#97803
ahmdshrif wants to merge 8 commits into
Expensify:mainfrom
ahmdshrif:sherif/issue-96073-proposal-71631c

Conversation

@ahmdshrif

@ahmdshrif ahmdshrif commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixes the infinite loading spinner reported when clicking the unlink validation link from a secondary-login email in a fresh browser tab. Three independent gaps caused this:

  1. UnlinkLoginPage exits via a bare Navigation.goBack(). A tab opened from the unlink email has UNLINK_LOGIN as the only route in the public stack, so canGoBack() is false and goBack() no-ops forever, leaving the spinner stuck. Fixed by resetting the stack to TAB_NAVIGATOR when there's nothing to pop back to — the same pattern ValidateLoginPage already uses for this exact situation, including its stale-callback cleanup guard.
  2. BaseLoginForm's mount effect unconditionally calls clearAccountMessages(), which wiped the "Secondary login successfully unlinked!" message before it could render. Fixed by scoping the skip to that one specific message value, leaving every other mount's cleanup unchanged.
  3. unlinkLogin's failureData never wrote an error, so a failed/expired unlink showed nothing. Fixed by writing unlinkLoginForm.unlinkError (added to all locale files) without touching credentials.login, so the failure correctly lands on UnlinkLoginForm, which already renders account.errors and has no mount-time clear.

Fixed Issues

$ #96073
PROPOSAL: #96073 (comment)

Tests

  1. Go to Settings → Profile, add a secondary email (don't verify it)
  2. Log in with the secondary email and click Unlink
  3. Open the Unlink Validation link email and click the link in a fresh browser tab
  4. Verify the tab lands on the sign-in page (not an infinite spinner) showing "Secondary login successfully unlinked!"
  5. Repeat with an expired/invalid unlink link and verify an error message renders on UnlinkLoginForm instead (with the resend/unlink affordance intact)
  6. Verify a native/pushed-stack deep link (canGoBack() true) still exits via the original goBack() path, unchanged
  • Verify that no errors appear in the JS console

Offline tests

This flow requires a live network round-trip to the unlink API to reach either terminal state (success or failure). I put an Android emulator into airplane mode and opened the unlink deep link: unlinkLogin's optimistic write sets isLoading: true and the request queues (standard Onyx offline-first behavior), so neither Navigation.goBack() nor the new stack-reset fires until the request actually settles — isLoading never flips to false while offline. That's unchanged from before this PR; nothing in this fix is offline-specific.

(Note: with the dev-debug build fully offline, Metro itself becomes unreachable and the JS bundle can't load at all — an artifact of the local dev harness, not the app or this fix, since a release build ships its bundle embedded.)

QA Steps

  1. Go to Settings → Profile, add a secondary email (don't verify it)
  2. Log in with the secondary email and click Unlink
  3. Open the Unlink Validation link email and click the link in a fresh browser tab (or a fresh mobile browser/incognito session)
  4. Verify the tab lands on the sign-in page instead of an infinite spinner, and shows "Secondary login successfully unlinked!"
  5. Repeat with an expired/already-used link and verify an error message renders instead of a blank/hung page

It's acceptable to write "Same as tests" if the QA team is able to run the tests in the above "Tests" section. Same as tests.

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

(No new CSS styles or assets were added or modified in this PR.)

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

(This PR does not modify any UI — no new buttons, components, spacing/padding changes, or form-input styles; it only wires an existing message-rendering path to a new trigger.)

Screenshots/Videos

Android: Native

unLink is not open on native

Android: mWeb Chrome Screenshot 2026-08-04 at 6 02 40 PM
iOS: Native

unLink is not open on native

iOS: mWeb Safari Simulator Screenshot - iPhone 16 Pro - 2026-08-04 at 15 26 27
MacOS: Chrome / Safari Screenshot 2026-08-04 at 3 24 33 PM

UNLINK_LOGIN is a standalone public screen with no route beneath it, so
a tab opened directly from the unlink email has an empty nav stack and
UnlinkLoginPage's bare Navigation.goBack() no-ops forever, leaving the
spinner stuck. Reset the stack to TAB_NAVIGATOR when there's nothing to
pop, matching the pattern ValidateLoginPage already uses for this.

Two more gaps kept the result invisible even once navigation worked:
BaseLoginForm's mount effect cleared account.message before the success
text could render, and unlinkLogin's failureData never wrote an error at
all, so a failed unlink showed nothing on UnlinkLoginForm either.
Covers UnlinkLoginPage's stack reset on a fresh tab (and the stale-
callback guard), BaseLoginForm's scoped clearAccountMessages skip for
the unlink success message (with a control case for ordinary stale
messages), and unlinkLogin's failureData now setting account.errors
without touching credentials.login.
…translated text

Without it translateLocal falls back to the raw key, since this action
test doesn't render a LocaleContextProvider to load translations.
@melvin-bot

melvin-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

…oposal-71631c

# Conflicts:
#	tests/actions/SessionTest.ts
@ahmdshrif

Copy link
Copy Markdown
Contributor Author

Translations were added manually in this PR — unlinkLoginForm.unlinkError is already present in all 10 locale files (en, es, de, nl, it, fr, ja, pl, zh-hans, pt-BR), so no automated generation is needed here.

- Reposition the naming-convention eslint-disable in BaseLoginForm.tsx:
  the merge's formatter reflowed the object literal and left the
  directive covering the wrong line, making it both unused and
  ineffective at once.
- Replace an unsafe HttpUtils.xhr cast in the new unlinkLogin test with
  jest.mocked(), which pushed the file's grandfathered
  no-unsafe-type-assertion count from 12 to 13.
- Drop an unused navigationRef import in UnlinkLoginPageTest.tsx.
- Add unlinkLoginForm.unlinkError to el.ts, a new locale file main added
  after this branch's translations were written.
- Simplify the canGoBack mock to a zero-arg call — spreading unknown[]
  into a function TypeScript infers as zero-arg doesn't type-check.
@ahmdshrif
ahmdshrif marked this pull request as ready for review August 4, 2026 16:53
@ahmdshrif
ahmdshrif requested review from a team as code owners August 4, 2026 16:53
@melvin-bot
melvin-bot Bot requested review from Pujan92 and trjExpensify August 4, 2026 16:54
@melvin-bot

melvin-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

@Pujan92 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]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 6268342b1e

ℹ️ 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 thread src/pages/signin/LoginForm/BaseLoginForm.tsx
Comment thread src/pages/signin/LoginForm/BaseLoginForm.tsx
…ge check

When an expired/invalid unlink link is opened in a browser that never
cached credentials.login for the flow (e.g. a different browser or
profile than the one that requested the unlink), shouldShowLoginForm
selects BaseLoginForm instead of UnlinkLoginForm. Its mount effect only
exempted the success message from clearAccountMessages(), so the
freshly-written unlink error was wiped before it could render, leaving
a blank sign-in form.

Extend the guard to also preserve that specific error by value, the
same way the success message is matched — not by testing account.errors
generally, which would strand unrelated stale errors on the page.

Also extract the repeated 'unlinkLoginForm.successfullyUnlinkedLogin'
literal (BaseLoginForm's accountMessage memo, its mount guard, and
UnlinkLoginForm's message check) into a single isUnlinkLoginSuccessMessage
predicate in SessionUtils so a future rename of the key can't silently
break one of the sites.
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/pages/UnlinkLoginPage.tsx 100.00% <100.00%> (+100.00%) ⬆️
src/pages/signin/LoginForm/BaseLoginForm.tsx 79.04% <100.00%> (+1.16%) ⬆️
... and 183 files with indirect coverage changes

Literal numeric object keys ({1: ...}) trip @typescript-eslint/naming-
convention. Switch to a computed key (Date.now()), matching how
production's ErrorUtils actually builds these error objects.
Comment thread src/libs/actions/Session/index.ts Outdated
key: ONYXKEYS.ACCOUNT,
value: {
isLoading: false,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('unlinkLoginForm.unlinkError'),

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.

I don't think we need this error as we do get it from the BE. Lets' remove this change

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.

Done — reverted, pushed in e6a738e. failureData is back to only flipping isLoading, since the BE's onyxData already supplies the error.

@Pujan92

Pujan92 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@ahmdshrif don't this change enough to fix the issue?

Screenshot 2026-08-05 at 19 14 20

@ahmdshrif

Copy link
Copy Markdown
Contributor Author

@Pujan92 Yes — that 3-line change (nav reset + the success-message guard + the failureData error write) is the complete fix for the reported issue, and matches the approved proposal exactly.

The extra bit in BaseLoginForm.tsx beyond that came from an automated Codex review on this PR, not from scope creep on my part: it flagged that a failed/expired unlink can also land on BaseLoginForm rather than UnlinkLoginForm — specifically when the link is opened in a browser/session that never cached credentials.login for that flow (e.g. a different browser or profile than the one that added the secondary email and requested the unlink). In that case the original guard only exempted the success message, so the freshly-written error got wiped by the same mount-clear effect, leaving a blank sign-in form instead of the error. I verified that repro live before fixing it, and it's a real (if narrower) instance of the same root cause.

The SessionUtils.isUnlinkLoginSuccessMessage extraction is a separate, small DRY cleanup — a second automated review flagged the raw translation-key literal being compared in three places (this guard, the accountMessage memo above it, and UnlinkLoginForm.tsx), which risks silently breaking one of them on a future key rename.

Happy to drop either or both if you'd rather keep this PR scoped strictly to the approved proposal — just say the word.

@Pujan92

Pujan92 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Yes, let's drop both changes at the moment as I think setting the error this way looks like a workaround to me.

Per @Pujan92's review: the backend already returns onyxData with a
proper error message on unlink failure, so a client-side generic
fallback (unlinkLoginForm.unlinkError) was redundant and looked like a
workaround rather than a fix. Reverting to the approved proposal's
scope:

- unlinkLogin's failureData goes back to only flipping isLoading.
- BaseLoginForm's mount-clear guard goes back to exempting only the
  success message, not a specific unlink error value.
- UnlinkLoginForm and the accountMessage memo go back to their inline
  literal comparisons (drops the isUnlinkLoginSuccessMessage extraction
  along with it, since it existed only to serve the guard above).
- Removes the now-unused unlinkLoginForm.unlinkError translation key
  from all locale files, and the tests that covered the reverted
  behavior.
@ahmdshrif

ahmdshrif commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@Pujan92 Pushed the revert (e6a738e) — back to the exact approved-proposal diff: nav reset + success-message guard only. Both extras (error-preservation guard + the DRY extraction that only existed to serve it) are gone, along with their tests and the now-unused unlinkLoginForm.unlinkError translation key.

@ahmdshrif
ahmdshrif requested a review from Pujan92 August 5, 2026 20:19
@Pujan92

Pujan92 commented Aug 6, 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: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

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.

2 participants