Skip to content

Inconsistent exception handling with multiple event handlers #8403

Closed
@adiguba

Description

@adiguba

Describe the bug

There is a difference in exceptions handling when multiple handlers are added on the same event of an element/component.

Imagine we add 3 handlers on the same element, like this :

    <button on:click={handler_01} on:click={handler_02} on:click={handler_03}> ... 

On a HTML node, if a handler fails for some reason and throw an error, its execution will logically be interrupted, but it has no impact on others handlers.

On a Svelte Component, a handler that throw an error will be interrupted, but will also prevent subsequent handlers from executing.

I think Svelte Components should mimic how native events work.

Reproduction

You can see a reproduction of this bug on this REPL :

https://svelte.dev/repl/a4c8c154000142b695f2a4011184dd12?version=3.57.0

There a 3 counters and 3 handlers that increments theses counters.
But the second handler will fail by throwing an error.

If these handlers are added to a <button>, they will all be executed (and all counter will increment)
If these handlers are added to a Component (via event bubbling (on:click) or createEventDispatcher), the last handler will never be executed (and his counter will not be incremented).

Logs

See reproduction

System Info

Svelte v3.57.0 (in REPL)

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions