diff --git a/src/lib/client/form.ts b/src/lib/client/form.ts index df83e020..942f75cc 100644 --- a/src/lib/client/form.ts +++ b/src/lib/client/form.ts @@ -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, @@ -120,6 +121,11 @@ export function Form, M>( completed({ cancelled: true }); }); + afterNavigate(() => { + ErrorTextEvents_removeErrorTextListeners(); + completed({ cancelled: false }); + }) + return { submitting() { Timers_start(); diff --git a/src/routes/(v2)/v2/issue-622/+layout.svelte b/src/routes/(v2)/v2/issue-622/+layout.svelte new file mode 100644 index 00000000..f0358604 --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/+layout.svelte @@ -0,0 +1,19 @@ + + +

Navigation

+ + +

Page id: {page.route.id}

+{@render children()} diff --git a/src/routes/(v2)/v2/issue-622/+page.svelte b/src/routes/(v2)/v2/issue-622/+page.svelte new file mode 100644 index 00000000..e69de29b diff --git a/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.server.ts b/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.server.ts new file mode 100644 index 00000000..5b4d000a --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.server.ts @@ -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") + } +} diff --git a/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.svelte b/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.svelte new file mode 100644 index 00000000..a083df7c --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/bad-with-workaround/+page.svelte @@ -0,0 +1,30 @@ + + +
+ +
+ + diff --git a/src/routes/(v2)/v2/issue-622/bad/+page.server.ts b/src/routes/(v2)/v2/issue-622/bad/+page.server.ts new file mode 100644 index 00000000..b5633e97 --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/bad/+page.server.ts @@ -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") + } +} diff --git a/src/routes/(v2)/v2/issue-622/bad/+page.svelte b/src/routes/(v2)/v2/issue-622/bad/+page.svelte new file mode 100644 index 00000000..63c84ae8 --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/bad/+page.svelte @@ -0,0 +1,35 @@ + + +
+ +
+ + diff --git a/src/routes/(v2)/v2/issue-622/good/+page.server.ts b/src/routes/(v2)/v2/issue-622/good/+page.server.ts new file mode 100644 index 00000000..390d37f5 --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/good/+page.server.ts @@ -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 } + } +} diff --git a/src/routes/(v2)/v2/issue-622/good/+page.svelte b/src/routes/(v2)/v2/issue-622/good/+page.svelte new file mode 100644 index 00000000..0527a087 --- /dev/null +++ b/src/routes/(v2)/v2/issue-622/good/+page.svelte @@ -0,0 +1,31 @@ + + +
+ +
+ +