diff --git a/.changeset/prompt-add-back-settimeout.md b/.changeset/prompt-add-back-settimeout.md new file mode 100644 index 0000000000..16e775931e --- /dev/null +++ b/.changeset/prompt-add-back-settimeout.md @@ -0,0 +1,5 @@ +--- +"react-router-dom": patch +--- + +[Remove] add back in `setTimeout` removal from `usePrompt` diff --git a/packages/react-router-dom/index.tsx b/packages/react-router-dom/index.tsx index cf12bca451..6150a864dc 100644 --- a/packages/react-router-dom/index.tsx +++ b/packages/react-router-dom/index.tsx @@ -1465,7 +1465,10 @@ function usePrompt({ when, message }: { when: boolean; message: string }) { if (blocker.state === "blocked") { let proceed = window.confirm(message); if (proceed) { - blocker.proceed(); + // This timeout is needed to avoid a weird "race" on POP navigations + // between the `window.history` revert navigation and the result of + // `window.confirm` + setTimeout(blocker.proceed, 0); } else { blocker.reset(); }