|
1 | 1 | import { enhance, applyAction } from '$app/forms'; |
2 | 2 | import { invalidateAll } from '$app/navigation'; |
3 | | -import { page } from '$app/stores'; |
| 3 | +import { navigating, page } from '$app/stores'; |
4 | 4 | import type { ActionResult } from '@sveltejs/kit'; |
5 | 5 | import { get, type Readable, type Writable } from 'svelte/store'; |
6 | 6 | import { browser } from '$app/environment'; |
@@ -548,19 +548,26 @@ export function formEnhance<T extends AnyZodObject, M>( |
548 | 548 | // Also fixing an edge case when timers weren't resetted when redirecting to the same route. |
549 | 549 | if (cancelled || result.type != 'redirect') { |
550 | 550 | htmlForm.completed(cancelled); |
551 | | - } else if ( |
552 | | - result.type == 'redirect' && |
553 | | - new URL( |
554 | | - result.location, |
555 | | - /^https?:\/\//.test(result.location) |
556 | | - ? undefined |
557 | | - : document.location.origin |
558 | | - ).pathname == document.location.pathname |
559 | | - ) { |
560 | | - // Checks if beforeNavigate have been called in client/form.ts. |
561 | | - setTimeout(() => { |
562 | | - htmlForm.completed(true, true); |
563 | | - }, 0); |
| 551 | + } else if (result.type == 'redirect') { |
| 552 | + if ( |
| 553 | + new URL( |
| 554 | + result.location, |
| 555 | + /^https?:\/\//.test(result.location) |
| 556 | + ? undefined |
| 557 | + : document.location.origin |
| 558 | + ).pathname == document.location.pathname |
| 559 | + ) { |
| 560 | + // Checks if beforeNavigate have been called in client/form.ts. |
| 561 | + setTimeout(() => { |
| 562 | + htmlForm.completed(true, true); |
| 563 | + }, 0); |
| 564 | + } else { |
| 565 | + const unsub = navigating.subscribe(($nav) => { |
| 566 | + if ($nav) return; |
| 567 | + unsub(); |
| 568 | + htmlForm.completed(cancelled); |
| 569 | + }); |
| 570 | + } |
564 | 571 | } |
565 | 572 | } |
566 | 573 |
|
|
0 commit comments