fix(react-router): symmetric pathname+search url comparison#31153
Open
EricHech wants to merge 1 commit into
Open
fix(react-router): symmetric pathname+search url comparison#31153EricHech wants to merge 1 commit into
EricHech wants to merge 1 commit into
Conversation
The leavingUrl/currentUrl comparison in handleHistoryChange used `leavingLocationInfo.pathname + leavingLocationInfo.search` on the left side but `location.pathname` (no search) on the right. For any route with a non-empty search string, the comparison was always unequal, so the transition block ran on every history event — including no-op popstates over same-URL entries (e.g. pushed via window.history.pushState). That triggered a false POP transition to the previous route while the browser URL stayed put. Compares pathname+search on both sides so the block runs only when the URL actually changed. Verified with a new Cypress regression that pushes a same-URL state on a search-bearing route, calls history.back(), and asserts the page does not teleport.
|
@EricHech is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #31152
What is the current behavior?
In
IonRouter.handleHistoryChange, the URL-change guard compares mismatched operands:The left side includes
search, the right side does not. For any route with a non-empty query string, the comparison is always unequal, so the transition block runs on every history event — including no-op popstates over same-URL entries pushed viawindow.history.pushState.Concretely: when a same-URL history entry on a search-bearing route is popped,
action === 'POP'is processed and the IRO transitions tocurrentRoute.pushedByRoute. The browser URL doesn't change but the rendered view does — the user gets silently teleported to a different page in the stack.Minimal repro: on any search-bearing route, run in the console:
The current behavior swaps the rendered page to the previous entry in
locationHistorywhile the URL stays put. Expected: no visible change.Full repro and analysis in #31152. This is also the root cause behind the symptom reported in #25534 (framed there as a transition-rerender flash).
What is the new behavior?
The right side of the comparison now also includes
search, so the block only runs when the URL actually changed:Behavior matrix:
routerPush(samePath + newSearch)): unchanged — pathname matches but search differs, block still runs.A new Cypress regression test is included (
packages/react-router/test/base/tests/e2e/specs/routing.cy.js) that pushes a same-URL state on a search-bearing route, callshistory.back(), and asserts the page does not teleport.Does this introduce a breaking change?
The comparison becomes stricter (skips the block in more cases than before), but only for the cases where the URL didn't actually change. All cases where the URL did change are still routed through the existing transition logic unchanged.
Other information
Happy to iterate on the fix shape if there's a preferred alternative — e.g. gating behind a flag for backward compat, or restructuring the guard differently. The one-line change above is the smallest possible fix that keeps existing behavior for every "real URL change" case.