Skip to content

new rule: svelte/no-add-event-listner #1194

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

Open
baseballyama opened this issue Apr 14, 2025 · 0 comments · May be fixed by #1197
Open

new rule: svelte/no-add-event-listner #1194

baseballyama opened this issue Apr 14, 2025 · 0 comments · May be fixed by #1197
Labels
enhancement New feature or request new rule

Comments

@baseballyama
Copy link
Member

baseballyama commented Apr 14, 2025

Motivation

We need to use on instead.
https://svelte.dev/docs/svelte/svelte-events#on

Description

Since Svelte 5 uses event delegation, using addEventListener may cause events to fire in unexpected order.
Therefore, we should always use on instead.

Examples

<script>
  import { on } from 'svelte/events';

  onMount(() => {
    // ✓ GOOD
    on(parent, 'click',() => {});
    // ✗ BAD
    parent.addEventListener('click',() => {});
  })
</script>

<div bind:this={parent}>
  <button />
</div>

Additional comments

No response

@baseballyama baseballyama added enhancement New feature or request new rule labels Apr 14, 2025
@baseballyama baseballyama changed the title no-add-event-listner new rule: svelte/no-add-event-listner Apr 14, 2025
@baseballyama baseballyama linked a pull request Apr 19, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant