Skip to content

fix(react-router): restore masked locations in hash history - #15771

Merged
brophdawg11 merged 2 commits into
remix-run:mainfrom
maxymlyskov:fix/restore-masked-locations-in-hash-history
Nov 20, 2026
Merged

brophdawg11 merged 2 commits into
remix-run:mainfrom
maxymlyskov:fix/restore-masked-locations-in-hash-history

Conversation

@maxymlyskov

Copy link
Copy Markdown
Contributor

The shared push/replace in getUrlBasedHistory write the mask into the URL (history.createHref(location.mask || location)) and the router location into history.state.masked, for every URL history. createBrowserLocation reads state.masked back (added with <Link unstable_mask> in #14716). createHashLocation only parses window.location.hash, so a hash history hands back the mask URL as the location with mask: undefined. That happens right after the push (history.location) and on every POP.

With createHashRouter and <Link to="/gallery?photo=123" mask="/images/123">, the click renders the gallery with the modal. Back/Forward to that entry renders the /images/:id route (the full image page) and useLocation().mask is undefined. The same app on createBrowserRouter goes back to the gallery + modal.

mask is documented for Data and Framework modes, and createHashRouter is a Data mode router.

I ran the built packages/react-router dist in jsdom (React 19.2.7, Node v22.23.3) with routes /, /gallery, /images/:id, /other: click the link, navigate to /other, history.back(). 3 runs, identical each time.

main 91ec73e07
hash:    back: image page (location /images/123, mask none) url #/images/123
browser: back: gallery+modal (location /gallery?photo=123, mask /images/123) url /images/123

this branch
hash:    back: gallery+modal (location /gallery?photo=123, mask /images/123) url #/images/123
browser: back: gallery+modal (location /gallery?photo=123, mask /images/123) url /images/123

This copies the browser history's read into createHashLocation. When history.state.masked is set, that is the location, and the path parsed from the hash (after the existing leading-/ normalisation) is passed as mask. history.ts is +3/-1. router.ts and lib.tsx are untouched: the router already pushes the mask and reads history.location on POP, and <Link mask> builds its href with the hash history's createHref.

Entries without a mask go through the same code as before and keep mask undefined.

Two new tests in hash-test.ts under a hash history → push a masked location: "shows the mask in the URL and keeps the router location" and "restores the router location on POP" (push masked, push /other, go(-1)). Both fail on main:

✕ shows the mask in the URL and keeps the router location (121 ms)
✕ restores the router location on POP (38 ms)
    - Expected  - 5
    + Received  + 1
    -   "mask": Object {
    -     "hash": "",
    +   "mask": undefined,
    -   },
    -   "pathname": "/gallery",
    -   "search": "?photo=123",
Tests:       2 failed, 19 skipped, 21 total

Both pass on the branch. Typecheck (pnpm run --filter react-router typecheck) is 0 errors on main and on the branch, and eslint, prettier and changes:validate pass.

Full pnpm build && pnpm test on the branch: 3443 passed, 3 failed, 15 skipped. All 3 failures are in special-characters-test.tsx, and that spec also fails on unmodified main (a different 2-3 of its param tests each run, across 3 runs).

push and replace write the mask into the URL and the router location
into history.state.masked for every URL history, but createHashLocation
never read it back. With createHashRouter and <Link mask>, Back/Forward
to a masked entry rendered the mask URL's route and location.mask was
undefined. Read state.masked the way createBrowserLocation does.

@brophdawg11 brophdawg11 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.

The hash-history read now follows createBrowserHistory’s masked-location behavior. The regressions cover push/replace and Back/Forward, preserving the visible mask and router location.

Authored by an AI agent on behalf of @brophdawg11

@brophdawg11
brophdawg11 merged commit 95ab714 into remix-run:main Nov 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants