From 206c6bc0a07c407f2e0a25981717afd113d877f9 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 18 Jul 2026 20:10:15 +0900 Subject: [PATCH] #399 --- frontend/src/lib/useUnsavedChangesGuard.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/useUnsavedChangesGuard.tsx b/frontend/src/lib/useUnsavedChangesGuard.tsx index b7848f7..6ba9f65 100644 --- a/frontend/src/lib/useUnsavedChangesGuard.tsx +++ b/frontend/src/lib/useUnsavedChangesGuard.tsx @@ -35,7 +35,7 @@ const UnsavedChangesGuardContext = export const UnsavedChangesGuardProvider: FC = ({ children }) => { const dialogue = useDialogue () const sourcesRef = useRef (new Map ()) - const bypassNextNavigationRef = useRef (false) + const bypassNextNavigationRef = useRef (null) const [revision, setRevision] = useState (0) const dialogueOpenRef = useRef (false) @@ -55,7 +55,13 @@ export const UnsavedChangesGuardProvider: FC = ({ children }) }, []) const allowNextNavigation = useCallback (() => { - bypassNextNavigationRef.current = true + const token = Symbol ('allowed-navigation') + bypassNextNavigationRef.current = token + + queueMicrotask (() => { + if (bypassNextNavigationRef.current === token) + bypassNextNavigationRef.current = null + }) }, []) const sources = useMemo ( @@ -68,16 +74,13 @@ export const UnsavedChangesGuardProvider: FC = ({ children }) ) const hasUnsavedChanges = dirtySources.length > 0 const shouldBlock = useCallback (() => { - if (!(hasUnsavedChanges)) - return false - - if (bypassNextNavigationRef.current) + if (bypassNextNavigationRef.current != null) { bypassNextNavigationRef.current = false return false } - return true + return hasUnsavedChanges }, [hasUnsavedChanges]) const blocker = useBlocker (shouldBlock)