Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/lib/client/form.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isElementInViewport, scrollToAndCenter } from './elements.js';
import type { FormOptions } from './superForm.js';
import { afterNavigate } from '$app/navigation';
import { onDestroy, tick } from 'svelte';
import type { Writable } from 'svelte/store';
import { isElementInViewport, scrollToAndCenter } from './elements.js';
import type { FormOptions } from './superForm.js';

enum FetchStatus {
Idle = 0,
Expand Down Expand Up @@ -120,6 +121,11 @@ export function Form<T extends Record<string, unknown>, M>(
completed({ cancelled: true });
});

afterNavigate(() => {
ErrorTextEvents_removeErrorTextListeners();
completed({ cancelled: false });
})

return {
submitting() {
Timers_start();
Expand Down
19 changes: 19 additions & 0 deletions src/routes/(v2)/v2/issue-622/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import { page } from '$app/state';

let { children } = $props();
</script>

<p>Navigation</p>
<ul>
<li><a href="/v2/issue-622/good?start">Good</a></li>
<li><a href="/v2/issue-622/bad?start">Bad</a></li>
<li>
<a href="/v2/issue-622/bad-with-workaround?start"
>Bad with workaround (timeoutMs > action delay)</a
>
</li>
</ul>

<p>Page id: {page.route.id}</p>
{@render children()}
Empty file.
24 changes: 24 additions & 0 deletions src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { zod as zod4 } from '$lib/adapters/zod4.js';
import { superValidate } from '$lib/index.js';
import { redirect } from '@sveltejs/kit';
import { z } from 'zod/v4';


const delay = (ms: number) => new Promise(r => setTimeout(r, ms))

const formId = "test-bad-with-workaround"

const ZodSchema = z.object({ hello: z.string() })
const FormSchema = zod4(ZodSchema)

export async function load() {
const form = await superValidate(FormSchema, { id: formId })
return { form }
}

export const actions = {
async default() {
await delay(5000)
redirect(302, "/v2/issue-622/bad-with-workaround")
}
}
30 changes: 30 additions & 0 deletions src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import { page } from '$app/stores';
import SuperDebug, { superForm } from '$lib/index.js';

let { data } = $props();

const form = superForm(data.form, {
dataType: 'json',
scrollToError: true,
autoFocusOnError: 'detect',
taintedMessage: false,
validationMethod: 'submit-only',
resetForm: false,
invalidateAll: false,
applyAction: true,
delayMs: 500,
timeoutMs: 10000
});
const { enhance, submitting, delayed, timeout, reset } = form;

const time = () => new Date().toISOString();

page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
</script>

<form method="post" use:enhance action="/v2/issue-622/bad-with-workaround?start">
<button>Submit</button>
</form>

<SuperDebug data={{ $submitting, $delayed, $timeout }} />
23 changes: 23 additions & 0 deletions src/routes/(v2)/v2/issue-622/bad/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { zod as zod4 } from '$lib/adapters/zod4.js';
import { superValidate } from '$lib/index.js';
import { redirect } from '@sveltejs/kit';
import { z } from 'zod/v4';

const delay = (ms: number) => new Promise(r => setTimeout(r, ms))

const formId = "test-bad"

const ZodSchema = z.object({ hello: z.string() })
const FormSchema = zod4(ZodSchema)

export async function load() {
const form = await superValidate(FormSchema, { id: formId })
return { form }
}

export const actions = {
async default() {
await delay(5000)
redirect(302, "/v2/issue-622/bad")
}
}
35 changes: 35 additions & 0 deletions src/routes/(v2)/v2/issue-622/bad/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import { afterNavigate } from '$app/navigation';
import { page } from '$app/stores';
import SuperDebug, { superForm } from '$lib/index.js';

let { data } = $props();

const form = superForm(data.form, {
dataType: 'json',
scrollToError: true,
autoFocusOnError: 'detect',
taintedMessage: false,
validationMethod: 'submit-only',
resetForm: false,
invalidateAll: false,
applyAction: true,
delayMs: 500,
timeoutMs: 1000,
onResult(event) {
console.log('onResult', event);
}
});
const { enhance, submitting, delayed, timeout, reset } = form;

const time = () => new Date().toISOString();

page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
afterNavigate((p) => console.log('afterNavigate', p));
</script>

<form method="post" use:enhance action="/v2/issue-622/bad?start">
<button>Submit</button>
</form>

<SuperDebug data={{ $submitting, $delayed, $timeout }} />
23 changes: 23 additions & 0 deletions src/routes/(v2)/v2/issue-622/good/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { zod as zod4 } from '$lib/adapters/zod4.js';
import { superValidate } from '$lib/index.js';
import { z } from 'zod/v4';

const delay = (ms: number) => new Promise(r => setTimeout(r, ms))

const formId = "test-good"

const ZodSchema = z.object({ hello: z.string() })
const FormSchema = zod4(ZodSchema)

export async function load() {
const form = await superValidate(FormSchema, { id: formId })
return { form }
}

export const actions = {
async default() {
await delay(5000)
const form = await superValidate(FormSchema, { id: formId })
return { form }
}
}
31 changes: 31 additions & 0 deletions src/routes/(v2)/v2/issue-622/good/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts">
import { page } from '$app/stores';
import SuperDebug, { superForm } from '$lib/index.js';

let { data } = $props();

const form = superForm(data.form, {
dataType: 'json',
scrollToError: true,
autoFocusOnError: 'detect',
taintedMessage: false,
validationMethod: 'submit-only',
resetForm: false,
invalidateAll: false,
applyAction: true,
delayMs: 500,

timeoutMs: 1000
});
const { enhance, submitting, delayed, timeout, reset } = form;

const time = () => new Date().toISOString();

page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
</script>

<form method="post" use:enhance action="/v2/issue-622/good?start">
<button>Submit</button>
</form>

<SuperDebug data={{ $submitting, $delayed, $timeout }} />