Repository navigation
[NoQA] Fix AI Features Promo modal SecurityError from doubled-slash path and re-entrancy - #97849
Conversation
…ard promo re-entrancy Co-authored-by: Cong Pham <suneox@users.noreply.github.com>
Co-authored-by: Cong Pham <suneox@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
There's no code fix to push — all code checks pass (all 8
So: the code is passing CI; both failures need human action (a review + the author checklist), not a commit. Evidence
|
|
Same result as my previous comment — nothing to push. Every code check is green (all 8
Both need human action (a review + the author checklist), not a commit. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariCleanShot.2026-08-07.at.18.00.38.1.mp4 |
|
@MelvinBot Please update the PR description before this is ready for review: Testsreplace the TODO with:
QA Stepsset to "Same as tests." Mark checked for all checkbox items, once both sections are filled, mark the PR ready for review. |
|
🤖 Updated the PR description and marked it ready for review.
The PR is no longer a draft. |
|
The only failing check is Every automated check on this PR is passing (tests, ESLint, Oxfmt, typecheck, React Compiler, Storybook, perf, To clear it: get the required independent review/approval on the PR. Once that's in place the check will pass automatically. |
mountiny
left a comment
There was a problem hiding this comment.
Would love to get @WojtekBoman @collectioneur @sumo-slonik to check this PR out as well before moving ahead
|
There's nothing to fix here in code — all real CI checks are green. The only failing check is Check independent approval, which isn't a test/lint/build failure. It's failing because GitHub still reports
This gate clears once an independent reviewer approves the PR; it can't be resolved by pushing a commit. Full check statusAll other checks pass — |
| if (lastRoute === NAVIGATORS.AI_FEATURES_PROMO_MODAL_NAVIGATOR) { | ||
| // The promo modal is already the active route (e.g. deep-linked directly). Re-navigating would | ||
| // append the suffix onto a base that already ends in it, producing a duplicated | ||
| // `…/ai-features-promo/ai-features-promo` path. Treat it as already shown and bail out. | ||
| hasRedirectedToAIFeaturesPromoModal = true; | ||
| return; | ||
| } |
There was a problem hiding this comment.
I wonder if this shouldn't be checked at a higher level, within the methods responsible for creating dynamic paths. I doubt there is a scenario where a dynamic path should be added again to the same path. Handling this at a higher level could help us avoid similar errors elsewhere in the future.
However, I think we can address this in a subsequent task if this PR needs to be merged urgently :)
There was a problem hiding this comment.
@MelvinBot can you create an issue for this and assign @collectioneur and @mountiny also include note about https://github.com/Expensify/App/pull/97849/changes#r3747400514
| // Mirror createDynamicRoute's slash handling: a root base (`/`) must not be concatenated with a leading slash, | ||
| // otherwise the result is a `//`-prefixed path that the browser parses as protocol-relative (host = first segment), | ||
| // making `history.pushState` throw a SecurityError. | ||
| const combinedPath = basePathWithoutQuery === '/' ? `/${suffixPath}` : `${basePathWithoutQuery}/${suffixPath}`; |
There was a problem hiding this comment.
NAB: Maybe we can extract a helper to return an adjusted path. I see that this logic is repeated elsewhere in the code
|
Re-checked — still nothing to fix in code. Every real CI check (Bun tests, The only non-passing checks are Current reviews: |
|
There's no code to fix — this is a stale check result from a race, not a real failure. The only failing check is Check independent approval (the Two things:
To clear it: just re-run the failed job — Re-run Every other check is green (Bun tests, all |
|
There's no code failure to fix — every CI check (tests, ESLint, Oxfmt, typecheck, React Compiler, Storybook, builds, perf, spellcheck, codecov) is green. The only red check is Check independent approval (the "Verify peer review" workflow), and it's a human review-gate, not something a code push can fix. Its log says exactly what's missing: What's needed: one approval from an independent Expensify employee ( |
mountiny
left a comment
There was a problem hiding this comment.
Thanks for the buddy check!
| if (lastRoute === NAVIGATORS.AI_FEATURES_PROMO_MODAL_NAVIGATOR) { | ||
| // The promo modal is already the active route (e.g. deep-linked directly). Re-navigating would | ||
| // append the suffix onto a base that already ends in it, producing a duplicated | ||
| // `…/ai-features-promo/ai-features-promo` path. Treat it as already shown and bail out. | ||
| hasRedirectedToAIFeaturesPromoModal = true; | ||
| return; | ||
| } |
There was a problem hiding this comment.
@MelvinBot can you create an issue for this and assign @collectioneur and @mountiny also include note about https://github.com/Expensify/App/pull/97849/changes#r3747400514
|
Done — created #98145 and assigned It tracks extracting a shared helper for the root-base slash-normalization logic that's duplicated across |
|
🚧 mountiny 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/mountiny in version: 9.4.52-0 🚀
|
|
🤖 No help site changes required. I reviewed the changes in this PR against Expensify's help site articles under Why: This PR is a purely internal fix for a
There are no new or changed features, UI labels, settings, tabs, buttons, or user-facing flows — nothing that any help article documents. The AI Features Promo modal continues to behave exactly as before for users; it simply no longer crashes when deep-linked. Because there is no documented behavior to add or correct, I did not open a draft docs PR. |
|
Seems it is an internal PR. |
|
all good, we will monitor in Sentry |
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.52-11 🚀
Bundle Size Analysis (Sentry): |
…hFromState This reverts the changes from Expensify#97849 so the SecurityError fix can be reimplemented as a single normalization step at the end of getPathFromState. Co-authored-by: Cong Pham <suneox@users.noreply.github.com>
Explanation of Change
Fixes the
SecurityError: Failed to execute 'pushState' on 'History'crash on/r/:reportID/ai-features-promo(Dynamic_AIFeaturesPromoModal_Root). Two independent defects combine to produce the crash, and this PR addresses both, per the approved proposal + updated fix:1. Doubled leading slash in the custom
getPathFromState(root cause of theSecurityError).The App's custom dynamic-route serializer concatenated the base path and the suffix by hand without normalizing the slash. When the base resolves to root (
/),`${basePathWithoutQuery}/${suffixPath}`produced//ai-features-promo. The browser reads a//-prefixed path as a protocol-relative URL and parses the first segment as the host, so the target origin becamehttps://ai-features-promo— a different origin thanhttps://new.expensify.com, andhistory.pushStatethrows aSecurityError. The fix mirrors the already-correct logic increateDynamicRoute.ts(normalizedBasePath === '/' ? '/' + suffixPath : ...) so a root base yields/ai-features-promo, never//ai-features-promo. The same normalization is applied to the tab-navigator branch a few lines up.2. Re-entrancy in
useAIFeaturesPromoModal(root cause of the doubledai-features-promo/ai-features-promosegment).The hook re-bases on
Navigation.getActiveRoute()and appends theai-features-promosuffix, but its only bail-outs wereSHARE_MODAL_NAVIGATORandSCREENS.NOT_FOUND— neither matches the promo modal navigator. When the promo modal was already the active route (e.g. deep-linked directly),getActiveRoute()already ended in the suffix, socreateDynamicRouteappended a second copy. The fix adds an "already on the promo modal" self-check (lastRoute === NAVIGATORS.AI_FEATURES_PROMO_MODAL_NAVIGATOR), mirroring the pattern the sibling guards already use, and treats an already-open promo as "already shown".Added a regression unit test in
getPathFromStateTests.tsverifying a root (/) base produces/test-dynamic, not//test-dynamic.Fixed Issues
$ #97470
PROPOSAL: #97470 (comment)
PROPOSAL: #97470 (comment)
Tests
page.routedelay)./r/<id>/ai-features-promo/using a non-existent reportID.SecurityError: Failed to execute 'pushState', and the URL is not doubled (it stays/r/<id>/ai-features-promo/, not…/ai-features-promo/ai-features-promo/).Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari