fix(admin): remove infinite loop in navigation guards
Fixed infinite loop caused by calling goto() inside beforeNavigate, which would trigger the same navigation guard again. The correct approach is to NOT cancel navigation, but simply await the autosave flush. SvelteKit's beforeNavigate accepts async callbacks, so navigation will naturally wait for the flush to complete before proceeding. Changes: - Removed navigation.cancel() calls - Removed goto() calls that created the loop - Simply await autoSave.flush() and let navigation proceed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8fa26fb39e
commit
128a24ccde
5 changed files with 5 additions and 27 deletions
|
|
@ -170,13 +170,9 @@ $effect(() => {
|
|||
if (autoSave.status === 'saved') {
|
||||
return
|
||||
}
|
||||
navigation.cancel()
|
||||
// Flush any pending changes before allowing navigation to proceed
|
||||
try {
|
||||
await autoSave.flush()
|
||||
// Navigate to the intended destination after flush completes
|
||||
if (navigation.to?.url) {
|
||||
goto(navigation.to.url.pathname + navigation.to.url.search)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Autosave flush failed:', error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,13 +174,9 @@ $effect(() => {
|
|||
if (autoSave.status === 'saved') {
|
||||
return
|
||||
}
|
||||
navigation.cancel()
|
||||
// Flush any pending changes before allowing navigation to proceed
|
||||
try {
|
||||
await autoSave.flush()
|
||||
// Navigate to the intended destination after flush completes
|
||||
if (navigation.to?.url) {
|
||||
goto(navigation.to.url.pathname + navigation.to.url.search)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Autosave flush failed:', error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,14 +185,9 @@
|
|||
return
|
||||
}
|
||||
|
||||
// Otherwise, flush any pending changes before navigating
|
||||
navigation.cancel()
|
||||
// Otherwise, flush any pending changes before allowing navigation to proceed
|
||||
try {
|
||||
await autoSave.flush()
|
||||
// Navigate to the intended destination after flush completes
|
||||
if (navigation.to?.url) {
|
||||
goto(navigation.to.url.pathname + navigation.to.url.search)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Autosave flush failed:', error)
|
||||
toast.error('Failed to save changes')
|
||||
|
|
|
|||
|
|
@ -175,13 +175,9 @@ beforeNavigate(async (navigation) => {
|
|||
if (autoSave.status === 'saved') {
|
||||
return
|
||||
}
|
||||
navigation.cancel()
|
||||
// Flush any pending changes before allowing navigation to proceed
|
||||
try {
|
||||
await autoSave.flush()
|
||||
// Navigate to the intended destination after flush completes
|
||||
if (navigation.to?.url) {
|
||||
goto(navigation.to.url.pathname + navigation.to.url.search)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Autosave flush failed:', error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -386,14 +386,9 @@ onMount(async () => {
|
|||
return
|
||||
}
|
||||
|
||||
// Otherwise, flush any pending changes before navigating
|
||||
navigation.cancel()
|
||||
// Otherwise, flush any pending changes before allowing navigation to proceed
|
||||
try {
|
||||
await autoSave.flush()
|
||||
// Navigate to the intended destination after flush completes
|
||||
if (navigation.to?.url) {
|
||||
goto(navigation.to.url.pathname + navigation.to.url.search)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Autosave flush failed:', error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue