fix: Fix invalid blocker state transition in UnsavedChangesProvider

Fix #1184: Time Unit error caused by invalid blocker state transition.

The error 'Invalid blocker state transition: unblocked -> proceeding' occurred
when calling blocker.proceed() in UnsavedChangesProvider.

Root cause: setDirty(false) was called before blocker.proceed?.(), which
triggered a re-render that could change the blocker state before proceed was
called. This caused React Router's internal state machine to receive a proceed
call when the blocker was no longer in the 'blocked' state.

Fix:
- Call blocker.proceed?.() before setDirty(false) in handleConfirm
- Add additional state check in isSamePathNavigation useEffect to ensure
  blocker is still 'blocked' before calling proceed()

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
karilint
2026-05-29 11:35:54 +03:00
parent 0b3ba3d759
commit 4ae003a540
@@ -72,8 +72,8 @@ export const UnsavedChangesProvider = ({
const handleConfirm = useCallback(() => {
if (blocker.state === 'blocked') {
setDirty(false)
blocker.proceed?.()
setDirty(false)
}
}, [blocker, setDirty])
@@ -91,7 +91,7 @@ export const UnsavedChangesProvider = ({
useEffect(() => {
const proceed = blocker.proceed as (() => void) | undefined
if (isSamePathNavigation && proceed) {
if (isSamePathNavigation && proceed && blocker.state === 'blocked') {
proceed()
}
}, [blocker, isSamePathNavigation])