Skip to content

Commit 9612a60

Browse files
fix: form action submit function callback return type (#13420)
* fix: add promise return type to enhance form action callback * remove unnecessary formatting change * fix: Dangling promise is now awaited * reapply fix --------- Co-authored-by: S. Elliott Johnson <[email protected]>
1 parent a09db8c commit 9612a60

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

.changeset/clean-dancers-type.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: add promise return type to the `enhance` action callback

packages/kit/src/exports/public.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ export type SubmitFunction<
14841484
* @param invalidateAll Set `invalidateAll: false` if you don't want the action to call `invalidateAll` after submission.
14851485
*/
14861486
update: (options?: { reset?: boolean; invalidateAll?: boolean }) => Promise<void>;
1487-
}) => void)
1487+
}) => MaybePromise<void>)
14881488
>;
14891489

14901490
/**

packages/kit/src/runtime/app/forms.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export function enhance(form_element, submit = () => {}) {
205205
result = { type: 'error', error };
206206
}
207207

208-
callback({
208+
await callback({
209209
action,
210210
formData: form_data,
211211
formElement: form_element,

packages/kit/test/apps/basics/src/routes/actions/enhance/+page.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
use:enhance={({ controller }) => {
3838
previous?.abort();
3939
previous = controller;
40-
return () => count++;
40+
return () => {
41+
count++;
42+
};
4143
}}
4244
>
4345
<button class="form2">Submit</button>

packages/kit/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ declare module '@sveltejs/kit' {
14661466
* @param invalidateAll Set `invalidateAll: false` if you don't want the action to call `invalidateAll` after submission.
14671467
*/
14681468
update: (options?: { reset?: boolean; invalidateAll?: boolean }) => Promise<void>;
1469-
}) => void)
1469+
}) => MaybePromise<void>)
14701470
>;
14711471

14721472
/**

0 commit comments

Comments
 (0)