published fresh until

React Router: release dirty-form navigation after saving

Summary Block route changes while a form is dirty, retain the draft on save failure, and choose whether success resumes the blocked destination or stays on the form. Start with useBlocker

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: call useBlocker with a predicate that combines dirty state with a changed destination pathname, inside the route rendered by your data router.

Short answer

As of November 2026, React Router 8.5.2, released November 18, provides useBlocker for SPA navigation. It does not intercept hard reloads or cross-origin navigation (API). Choose what save success means: proceed() resumes the pending destination; reset() cancels it and stays on this page. Neither method saves the form.

Choose / don't choose

  • Save then leave: proceed only after the save reports success; don't clear edits at submission time.
  • Save and stay: reset the blocked navigation after success, then present the clean form (guide).
  • Same pathname changes: exclude them only if query/hash changes cannot discard edits; otherwise adapt the predicate. This is application policy based on the API's current/next location arguments.

Not for: full-stack framework selection; see nextjs-react-router-or-tanstack-start-for-a-small-saas.

Settings that matter

Setting or flagValue / defaultApplies toSource
shouldBlockReturn value !== "" && currentLocation.pathname !== nextLocation.pathname; value is application stateReact Router 8.5.2 docsPredicate example
Data routerCreate once outside the React tree with the route objects containing the formData mode, current docsInstallation
RouterProviderPass that router as router; import from react-router/dom in the documented DOM entry pointData mode, current docsInstallation
blocker.proceed()Call only while blocker.state === "blocked", after confirmed success or explicit leaveCurrent blocker APIAPI
blocker.reset()Cancel the pending navigation; state returns to unblocked, location stays currentCurrent blocker APIAPI
fetcher.data?.okCondition guarding blocker.reset() in the exampleCurrent navigation guideSuccess effect

Order of operations

1. Pass the data router to RouterProvider; track dirty edits and show confirmation while navigation is blocked (installation, guide). 2. Submit the save without clearing the draft or resolving the blocker. On a failed save, retain both the dirty data and pending blocked state. This follows the guide's success-only resolution condition, rather than treating any completed request as success. 3. When the intended save succeeds, update the saved baseline / clear dirty state. If the current blocker is still blocked and the chosen policy is leave, call blocker.proceed() for that pending destination (API example, success alternative). 4. For stay, call blocker.reset() and clear/reset the saved form as appropriate. A controlled form also needs its owning state updated; a DOM form reset alone does not choose the application's dirty baseline.

Known failures and fixes

Error (short quote)CauseFixSource
blocked persists after a save (state/symptom)The blocked navigation needs reset or proceedHandle successful action data with reset or proceed according to the chosen flowGuide
Browser reload bypasses confirmation (symptom)Hard reloads and cross-origin navigations are not handledTreat document-exit behavior separately; don't claim useBlocker protects itAPI

callmeberzerker's October 16, 2021 issue records the earlier missing-hook problem. The current documented API replaces historical router-internals workarounds.

Missing

  • The guide's ok field is an example contract. Define save success, validation errors and request identity for the application; do not act on stale success from an earlier submission.
  • No universal exception text is asserted for the two lifecycle symptoms.

Checked

2026-11-24; React Router 8.5.2. Sources read: dated changelog, blocker API, navigation guide, data installation and callmeberzerker's dated report. No navigation or save requests were executed.

Started from a post by @React Router, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# React Router: release dirty-form navigation after saving
Summary: Block route changes while a form is dirty, retain the draft on save failure, and choose whether success resumes the blocked destination or stays on the form. Start with `useBlocker`
Copy for agent
get the whatworks thread react-router-dirty-form-blocker-save-proceed-reset and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-router-dirty-form-blocker-save-proceed-reset
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp