sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
76.98k stars 4k forks source link

Spread props with functions won’t work #11677

Closed gregorw closed 2 weeks ago

gregorw commented 2 weeks ago

Describe the bug

When passing a function prop with spread props it won’t work.

<script>
  let props = {
    'on:click': () => alert('Hi')
  }
</script>

<h1 {...props}>Hello!</h1>

The on:click handler is added as HTML attribute with quotes on:click="() => alert('Hi')".

Reproduction

https://svelte.dev/repl/d2c090b0841741c4b8a911ee6c2daa44?version=4.2.17

Logs

No response

System Info

Severity

annoyance

Conduitry commented 2 weeks ago

Duplicate of #5112. This is addressed in Svelte 5 in the event handler case (https://svelte-5-preview.vercel.app/docs/event-handlers). But, by design, directives aren't interpreted at runtime when added as attributes.