Open
Description
- [✓] Before posting an issue, read the FAQ and search the previous issues.
Description
When events
are added to use:enhance
, if the form element is created and destroyed multiple times (for example, the form is in a sheet
or dialog
or, even simpler, in an if
like in the MRE below), the events are pushed multiple times to formEvents
but never destroyed.
MRE
In that example, if you toggle the form multiple times, you can see that onUpdated
is called multiple times
Possible solution
Instead of returning kitEnhance here :
sveltekit-superforms/src/lib/client/superForm.ts
Line 1605 in 1b7a158
it could be something like this :
const enhance = kitEnhance("...");
return {
destroy: () => {
// same as in onDestroy()
for (const events of Object.values(formEvents)) {
events.length = 0;
}
// call native enhance destroy
enhance.destroy();
}
}
What are your thoughts?
By the way, thank you again for this awesome library.
Metadata
Metadata
Assignees
Labels
No labels