Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge main and strengthen masked hash history regressions
  • Loading branch information
brophdawg11 committed Nov 20, 2026
commit 268ce0b543229c8eef13d351b65a77093c61924d
61 changes: 42 additions & 19 deletions packages/react-router/__tests__/router/hash-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,44 +167,67 @@ describe("a hash history", () => {
});
});

describe("push a masked location", () => {
describe("masked locations", () => {
let gallery: Location = {
pathname: "/gallery",
search: "?photo=123",
hash: "",
state: null,
hash: "#photo",
state: { source: "gallery" },
key: "gallery",
mask: { pathname: "/images/123", search: "", hash: "" },
mask: {
pathname: "/images/123",
search: "?size=large",
hash: "#preview",
},
};

it("shows the mask in the URL and keeps the router location", () => {
it("shows the mask in the URL and keeps the router location on push and replace", () => {
history.push(gallery);
expect(testWindow.location.hash).toEqual("#/images/123");
expect(history.location).toMatchObject({
pathname: "/gallery",
search: "?photo=123",
mask: { pathname: "/images/123", search: "", hash: "" },
});
});

it("restores the router location on POP", async () => {
expect(testWindow.location.hash).toEqual(
"#/images/123?size=large#preview",
);
expect(history.location).toEqual(gallery);

let nextGallery: Location = {
...gallery,
search: "?photo=456",
key: "next-gallery",
mask: { pathname: "/images/456", search: "", hash: "" },
};
history.replace(nextGallery);
expect(testWindow.location.hash).toEqual("#/images/456");
expect(history.location).toEqual(nextGallery);
});

it("restores masked and unmasked locations on POP", async () => {
history.push(gallery);
history.push("/other");
let other = history.location;

// JSDom doesn't fire the listener synchronously
let popped = new Promise<Location>((resolve) => {
let back = new Promise<Location>((resolve) => {
let unlisten = history.listen(({ location }) => {
unlisten();
resolve(location);
});
});
history.go(-1);
expect(await back).toEqual(gallery);
expect(history.location).toEqual(gallery);
expect(testWindow.location.hash).toEqual(
"#/images/123?size=large#preview",
);

expect(await popped).toMatchObject({
pathname: "/gallery",
search: "?photo=123",
mask: { pathname: "/images/123", search: "", hash: "" },
let forward = new Promise<Location>((resolve) => {
let unlisten = history.listen(({ location }) => {
unlisten();
resolve(location);
});
});
history.go(1);
expect(await forward).toEqual(other);
expect(history.location.mask).toBeUndefined();
expect(testWindow.location.hash).toEqual("#/other");
});
});
});
You are viewing a condensed version of this merge commit. You can view the full changes here.