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

Svelte 5 Docs: Clarify underlying implementation of event handler property usage #11317

Open
willnationsdev opened this issue Apr 24, 2024 · 1 comment
Milestone

Comments

@willnationsdev
Copy link

willnationsdev commented Apr 24, 2024

Describe the problem

With the transition to callback props for event handlers instead of on:, I cannot tell from the docs whether an event handler for onclick overrides the actual onclick property or uses the core methods addEventListener("click") and removeEventListener("click"), especially given how the docs warn against assigning to the same event twice.

This is concerning to me since I must account for 3rd-party code outside of Svelte & my own code that may attempt to add handlers for the same events my Svelte components manipulate.

Describe the proposed solution

I assume that the underlying implementation uses the core methods to register events; if not, that in itself would be very concerning to me & deserving of its own GitHub issue. Otherwise...

I would like for the documentation about event handlers to be more explicit about...

  1. How event handlers are registered (so people like me aren't confused).
  2. When the add & remove calls are made in the component lifecycle.
  3. How event handlers can safely be manipulated by third-party code.
    1. Can client-side APIs directly use the core methods on components safely?
    2. If not, does Svelte plan to expose a custom API for doing so?

Importance

would make my life easier

@dummdidumm dummdidumm added this to the 5.0 milestone Apr 29, 2024
@dummdidumm
Copy link
Member

We're using addEventListener under the hood, yes.
I'm not sure we need to get into that much detail in the docs, but we can certainly mention that it uses event delegation and/or addEventListener under the hood, and that event handlers are always applied after bindings event listeners (if present).

Point 3 is a bit confusing to me - I don't know what you mean by that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants