Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
test: expand useBlocker mount navigation coverage
Cover StrictMode, router recreation, Activity, and server rendering.
Tighten the effect timing comment and patch change note.
  • Loading branch information
brophdawg11 committed Nov 20, 2026
commit 0966988819f5c732656ebf1d4f7dbdd99b521078
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Fix `useBlocker` blocking a second time when the destination route updates search params on mount

- The blocker function is now registered with the router in a layout effect, so a navigation started from another component's mount effect is never checked against a stale blocker function
Fix `useBlocker` blocking a second time when the destination route updates search params in a mount effect
33 changes: 33 additions & 0 deletions packages/react-router/__tests__/dom/data-static-router-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useLoaderData,
useLocation,
useMatches,
useBlocker,
createStaticHandler,
createStaticRouter,
StaticRouterProvider,
Expand All @@ -23,6 +24,38 @@ beforeEach(() => {
});

describe("A <StaticRouterProvider>", () => {
it("renders an unblocked blocker without registering it on the server", async () => {
let shouldBlock = jest.fn(() => true);
let routes = [
{
path: "/",
Component() {
let blocker = useBlocker(shouldBlock);
return <p>{blocker.state}</p>;
},
},
];
let { query } = createStaticHandler(routes);
let context = (await query(
new Request("http://localhost/"),
)) as StaticHandlerContext;
let router = createStaticRouter(routes, context);

let html = ReactDOMServer.renderToString(
<StaticRouterProvider
router={router}
context={context}
hydrate={false}
/>,
);

expect(html).toBe("<p>unblocked</p>");
expect(shouldBlock).not.toHaveBeenCalled();
expect(router.state.blockers.size).toBe(0);
expect(console.error).not.toHaveBeenCalled();
expect(console.warn).not.toHaveBeenCalled();
});

it("reuses the static handler route matcher", async () => {
let { query } = createStaticHandler([
{
Expand Down
Loading