Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormControlController accumulates eventListeners #2376

Open
nathangray opened this issue Feb 13, 2025 · 0 comments
Open

FormControlController accumulates eventListeners #2376

nathangray opened this issue Feb 13, 2025 · 0 comments
Labels
bug Things that aren't working right in the library.

Comments

@nathangray
Copy link
Contributor

Describe the bug

If you have a dynamic form where elements are added and removed, the <form> element continuously gets event listeners bound, but they aren't all cleared when a component is removed. If the component has assume interactions, those are removed.
Every new component adds to the form's formdata, submit & reset handlers.

See https://github.com/shoelace-style/shoelace/blob/next/src/internal/form.ts#L187
Only when the last element is removed from the form are all these handlers removed.

To Reproduce

Steps to reproduce the behavior:

See the demo.

  1. Have a form with an input
  2. Add more input(s). Each input binds event handlers on the form
  3. Remove all but 1 input. The event handlers from previously removed components are still there.

Demo

https://codepen.io/nathangray-the-flexboxer/pen/YPzPjWZ?editors=1000
If you use developer tools inspect the form, you can see that while the form has 1 input, it has 101 listeners bound.

Screenshots

Image

Additional information

Our use involves many components being added and removed over time, and its possible for a user to go for several hours without actually submitting the form. This causes quite a buildup in memory.

@nathangray nathangray added the bug Things that aren't working right in the library. label Feb 13, 2025
nathangray added a commit to EGroupware/egroupware that referenced this issue Feb 14, 2025
nathangray added a commit to EGroupware/egroupware that referenced this issue Feb 14, 2025
- Work-around for shoelace-style/shoelace#2376
- Fix some missing cleanup & a few other minor improvements for etemplate widgets
- Stop egw from holding on to registered plugins (& every instance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

1 participant