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: mixing and matching old and new events is buggy #11262

Closed
Rich-Harris opened this issue Apr 20, 2024 · 2 comments · Fixed by #11295
Closed

Svelte 5: mixing and matching old and new events is buggy #11262

Rich-Harris opened this issue Apr 20, 2024 · 2 comments · Fixed by #11295
Labels
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the bug

If you have both onclick and on:click in the same component...

<script>
  let count = $state(0);

  function increment() {
    count += 1;
  }
</script>

<button onclick={increment}>
  clicks: {count}
</button>

<button on:click={increment}>
  clicks: {count}
</button>

...the generated code is buggy — the handler is incorrectly hoisted, and count is undefined for the second handler.

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE5WPwQrCMBBEfyUEDy0K6jW2gt9hPNR0C8F2E5KNICH_bpKCgjePM7Nvlol80jN4Lq6R47AAF_xiLd9xetki_BNmgqy9CU4Vp_PKaUtniZJmIKZMQGI923gaCJpDe8pJzqaAirRBplE5WACpaVksiaSV2fbsWI4pSez231rs7oEokwbVrNWjj5-KVN9W1wsWa0-lV-KHFv_ieediRj1pGLkgFyDd0hvqXqI4IgEAAA==

Logs

No response

System Info

next

Severity

annoyance

@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 20, 2024
@dummdidumm
Copy link
Member

Should we do the same we do when mixing slots and render tags and error (but only on element handlers, components might not be under the author's control)

@Rich-Harris
Copy link
Member Author

That seems reasonable, yeah

dummdidumm added a commit that referenced this issue Apr 28, 2024
Closes #11262

---------

Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants