Skip to content

Deprecate events passed to enhance? #466

Open
@gbouteiller

Description

@gbouteiller
  • [✓] 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 :

return kitEnhance(FormElement, async (submitParams) => {

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions