Skip to content

Commit a32810d

Browse files
test: issue reproduction forms
1 parent 5851fdd commit a32810d

File tree

8 files changed

+185
-0
lines changed

8 files changed

+185
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import { page } from '$app/state';
3+
4+
let { children } = $props();
5+
</script>
6+
7+
<p>Navigation</p>
8+
<ul>
9+
<li><a href="/v2/issue-622/good?start">Good</a></li>
10+
<li><a href="/v2/issue-622/bad?start">Bad</a></li>
11+
<li>
12+
<a href="/v2/issue-622/bad-with-workaround?start"
13+
>Bad with workaround (timeoutMs > action delay)</a
14+
>
15+
</li>
16+
</ul>
17+
18+
<p>Page id: {page.route.id}</p>
19+
{@render children()}

src/routes/(v2)/v2/issue-622/+page.svelte

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { zod as zod4 } from '$lib/adapters/zod4.js';
2+
import { superValidate } from '$lib/index.js';
3+
import { redirect } from '@sveltejs/kit';
4+
import { z } from 'zod/v4';
5+
6+
7+
const delay = (ms: number) => new Promise(r => setTimeout(r, ms))
8+
9+
const formId = "test-bad-with-workaround"
10+
11+
const ZodSchema = z.object({ hello: z.string() })
12+
const FormSchema = zod4(ZodSchema)
13+
14+
export async function load() {
15+
const form = await superValidate(FormSchema, { id: formId })
16+
return { form }
17+
}
18+
19+
export const actions = {
20+
async default() {
21+
await delay(5000)
22+
redirect(302, "/v2/issue-622/bad-with-workaround")
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores';
3+
import SuperDebug, { superForm } from '$lib/index.js';
4+
5+
let { data } = $props();
6+
7+
const form = superForm(data.form, {
8+
dataType: 'json',
9+
scrollToError: true,
10+
autoFocusOnError: 'detect',
11+
taintedMessage: false,
12+
validationMethod: 'submit-only',
13+
resetForm: false,
14+
invalidateAll: false,
15+
applyAction: true,
16+
delayMs: 500,
17+
timeoutMs: 10000
18+
});
19+
const { enhance, submitting, delayed, timeout, reset } = form;
20+
21+
const time = () => new Date().toISOString();
22+
23+
page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
24+
</script>
25+
26+
<form method="post" use:enhance action="/v2/issue-622/bad-with-workaround?start">
27+
<button>Submit</button>
28+
</form>
29+
30+
<SuperDebug data={{ $submitting, $delayed, $timeout }} />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { zod as zod4 } from '$lib/adapters/zod4.js';
2+
import { superValidate } from '$lib/index.js';
3+
import { redirect } from '@sveltejs/kit';
4+
import { z } from 'zod/v4';
5+
6+
const delay = (ms: number) => new Promise(r => setTimeout(r, ms))
7+
8+
const formId = "test-bad"
9+
10+
const ZodSchema = z.object({ hello: z.string() })
11+
const FormSchema = zod4(ZodSchema)
12+
13+
export async function load() {
14+
const form = await superValidate(FormSchema, { id: formId })
15+
return { form }
16+
}
17+
18+
export const actions = {
19+
async default() {
20+
await delay(5000)
21+
redirect(302, "/v2/issue-622/bad")
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script lang="ts">
2+
import { afterNavigate } from '$app/navigation';
3+
import { page } from '$app/stores';
4+
import SuperDebug, { superForm } from '$lib/index.js';
5+
6+
let { data } = $props();
7+
8+
const form = superForm(data.form, {
9+
dataType: 'json',
10+
scrollToError: true,
11+
autoFocusOnError: 'detect',
12+
taintedMessage: false,
13+
validationMethod: 'submit-only',
14+
resetForm: false,
15+
invalidateAll: false,
16+
applyAction: true,
17+
delayMs: 500,
18+
timeoutMs: 1000,
19+
onResult(event) {
20+
console.log('onResult', event);
21+
}
22+
});
23+
const { enhance, submitting, delayed, timeout, reset } = form;
24+
25+
const time = () => new Date().toISOString();
26+
27+
page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
28+
afterNavigate((p) => console.log('afterNavigate', p));
29+
</script>
30+
31+
<form method="post" use:enhance action="/v2/issue-622/bad?start">
32+
<button>Submit</button>
33+
</form>
34+
35+
<SuperDebug data={{ $submitting, $delayed, $timeout }} />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { zod as zod4 } from '$lib/adapters/zod4.js';
2+
import { superValidate } from '$lib/index.js';
3+
import { z } from 'zod/v4';
4+
5+
const delay = (ms: number) => new Promise(r => setTimeout(r, ms))
6+
7+
const formId = "test-good"
8+
9+
const ZodSchema = z.object({ hello: z.string() })
10+
const FormSchema = zod4(ZodSchema)
11+
12+
export async function load() {
13+
const form = await superValidate(FormSchema, { id: formId })
14+
return { form }
15+
}
16+
17+
export const actions = {
18+
async default() {
19+
await delay(5000)
20+
const form = await superValidate(FormSchema, { id: formId })
21+
return { form }
22+
}
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores';
3+
import SuperDebug, { superForm } from '$lib/index.js';
4+
5+
let { data } = $props();
6+
7+
const form = superForm(data.form, {
8+
dataType: 'json',
9+
scrollToError: true,
10+
autoFocusOnError: 'detect',
11+
taintedMessage: false,
12+
validationMethod: 'submit-only',
13+
resetForm: false,
14+
invalidateAll: false,
15+
applyAction: true,
16+
delayMs: 500,
17+
18+
timeoutMs: 1000
19+
});
20+
const { enhance, submitting, delayed, timeout, reset } = form;
21+
22+
const time = () => new Date().toISOString();
23+
24+
page.subscribe((v) => console.log(`${time()}: Page store update`, { page: v }));
25+
</script>
26+
27+
<form method="post" use:enhance action="/v2/issue-622/good?start">
28+
<button>Submit</button>
29+
</form>
30+
31+
<SuperDebug data={{ $submitting, $delayed, $timeout }} />

0 commit comments

Comments
 (0)