Skip to content

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

@willnationsdev

Description

@willnationsdev

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions