File tree Expand file tree Collapse file tree
src/app/editor/[id]/[slug] Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ import { useDialogs } from "@/components/ui/dialog-provider";
55
66const LEAVE_MESSAGE = "You have unsaved changes. Leave this page without saving?" ;
77
8+ // Next.js internally sets an auto-incrementing `idx` on history.state to track
9+ // navigation position. This is an undocumented internal — not a public API — so
10+ // it may disappear or change in any Next.js release. We use it to determine
11+ // whether the user navigated forward or back so we can revert the navigation
12+ // when they cancel. If `idx` is absent we degrade gracefully (warn, but can't
13+ // revert). See: https://github.com/vercel/next.js/discussions/34980
814function getCurrentHistoryIndex ( ) {
915 const historyState = window . history . state as { idx ?: number } | null ;
1016 return typeof historyState ?. idx === "number" ? historyState . idx : null ;
@@ -20,17 +26,11 @@ export function useUnsavedChangesGuard(isDirty: boolean) {
2026 return true ;
2127 }
2228
23- const shouldLeave = await confirm ( {
29+ return await confirm ( {
2430 message : LEAVE_MESSAGE ,
2531 actionLabel : "Leave" ,
2632 destructive : true ,
2733 } ) ;
28-
29- if ( ! shouldLeave ) {
30- return false ;
31- }
32-
33- return true ;
3434 } , [ confirm , isDirty ] ) ;
3535
3636 useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments