Skip to content

Commit ffee194

Browse files
committed
fix: clear stale preflight issues on subsequent valid form submissions
Fixes #15181
1 parent 3cbaac2 commit ffee194

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: clear stale preflight issues on subsequent valid form submissions

packages/kit/src/runtime/client/remote-functions/form.svelte.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export function form(id) {
121121
return;
122122
}
123123

124+
// Preflight passed - clear stale client-side preflight issues
125+
if (preflight_schema) {
126+
raw_issues = raw_issues.filter((issue) => issue.server);
127+
}
128+
124129
// TODO 3.0 remove this warning
125130
if (DEV) {
126131
const error = () => {

packages/kit/test/apps/async/src/routes/remote/form/preflight/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { tick } from 'svelte';
23
import { get_number, set_number } from './form.remote.js';
34
import * as v from 'valibot';
45
@@ -35,6 +36,10 @@
3536
<form
3637
data-enhanced
3738
{...enhanced.preflight(schema).enhance(async ({ submit }) => {
39+
await tick();
40+
if (enhanced.fields.number.issues()) {
41+
return;
42+
}
3843
await submit();
3944
})}
4045
>

packages/kit/test/apps/async/test/test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,32 @@ test.describe('remote functions', () => {
201201
);
202202
});
203203

204-
test('form preflight works', async ({ page, javaScriptEnabled }) => {
204+
test.only('form preflight works', async ({ page, javaScriptEnabled }) => {
205205
if (!javaScriptEnabled) return;
206206

207207
await page.goto('/remote/form/preflight');
208208

209209
for (const enhanced of [true, false]) {
210-
const input = page.locator(enhanced ? '[data-enhanced] input' : '[data-default] input');
210+
const form = page.locator(enhanced ? '[data-enhanced]' : '[data-default]');
211+
const input = form.locator('input');
211212
const button = page.getByText(enhanced ? 'set enhanced number' : 'set number');
212213

213214
await input.fill('21');
214215
await button.click();
215-
await page.getByText('too big').waitFor();
216+
await form.getByText('too big').waitFor();
216217

217218
await input.fill('9');
218219
await button.click();
219-
await page.getByText('too small').waitFor();
220+
await form.getByText('too small').waitFor();
221+
await expect(form.getByText('too big')).not.toBeVisible();
222+
223+
if (enhanced) {
224+
// one more time preflight-issue only so that we can test it's cleared
225+
// after it passes and before submission.
226+
await input.fill('21');
227+
await button.click();
228+
await form.getByText('too big').waitFor();
229+
}
220230

221231
await input.fill('15');
222232
await button.click();

0 commit comments

Comments
 (0)