-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
fix: properly remove event listeners in Component's removeEventListener (v4) #13556
base: svelte-4
Are you sure you want to change the base?
Conversation
ovx
commented
Oct 10, 2024
•
edited
Loading
edited
- fix: properly remove event listeners in Component's removeEventListener
|
The event listeners are not properly removed when using The issue is painfully obvious when using a WebComponent (built form a Svelte component) in React with strict mode enabled, where the component is mounted twice resulting in the listener being attached twice without the first one being removed. Example: const button = document.querySelector('my-button');
const handler = () => {
console.log('myaction handler');
};
// add and remove, simulating React's strict mode
button.addEventListener('myaction', handler);
button.removeEventListener('myaction', handler);
// only add
button.addEventListener('myaction', handler); The code above does not remove the first listener, firing the handler twice. |
it looks like you published copies of svelte and vite-plugin-svelte to the public npm registry, keeping the original metadata for repository and license etc. in place. This can be confusing for both users and tools (eg github now shows your plugin as first if you look up the dependents of vite-plugin-svelte https://github.com/sveltejs/vite-plugin-svelte/network/dependents) Please remove/make them private or update all metadata to make it clear they are not provided by the svelte org but forks. |
Can you provide a reproduction of the bug? I'm not exactly sure what this is fixing. Thanks |
Reproduction mentioned in the comment #13556 (comment) What is it fixing: The code above does not remove the first listener, firing the handler twice. Note: This is just for Svelte 4; It works fine in Svelte 5. |
That's not a reproduction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not reviewing this for so long - the fix makes sense (there's a memory leak with listeners never getting removed from the $$l[type]
array), just needs a changeset and then it's good to go. Though we need to make sure we're not tagging this release as latest (it's for Svelte 4).