このコミットが含まれているのは:
2026-07-18 20:10:15 +09:00
コミット 206c6bc0a0
+10 -7
ファイルの表示
@@ -35,7 +35,7 @@ const UnsavedChangesGuardContext =
export const UnsavedChangesGuardProvider: FC<PropsWithChildren> = ({ children }) => {
const dialogue = useDialogue ()
const sourcesRef = useRef (new Map<symbol, UnsavedChangesSource> ())
const bypassNextNavigationRef = useRef (false)
const bypassNextNavigationRef = useRef<symbol | null> (null)
const [revision, setRevision] = useState (0)
const dialogueOpenRef = useRef (false)
@@ -55,7 +55,13 @@ export const UnsavedChangesGuardProvider: FC<PropsWithChildren> = ({ 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<PropsWithChildren> = ({ 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)