-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
first pointed out in #7581 by @NormandoHall
Passing an async function as the parameter for the enhance action throws an error. Therefore, the async function runs but fails to return the callback function that is called after the form submission.
<form use:enhance={async () => {
// function runs as as expected
// ...
// the returned callback function never runs
return () => {}
}}>The browser error below displays because the returned value of an async function becomes a Promise instead of the expected callback function.

I've submitted a PR to await the function passed to the enhance action parameter.
Reproduction
Submitting the form causes an error in the browser console and the returned callback never runs.
Logs
forms.js?v=48b077e5:100
Uncaught (in promise) TypeError: callback is not a function
at HTMLFormElement.handle_submit (forms.js?v=48b077e5:100:3)
handle_submit @ forms.js?v=48b077e5:100System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.87
@sveltejs/kit: next => 1.0.0-next.539
svelte: ^3.46.0 => 3.53.1
vite: ^3.1.0 => 3.2.3Severity
serious, but I can work around it
Additional Information
The current workaround is to implement the progressive enhancement manually.
https://kit.svelte.dev/docs/form-actions#progressive-enhancement-custom-event-listener