svelte icon indicating copy to clipboard operation
svelte copied to clipboard

svelte 5: unnecessary code generated for updates

Open Rich-Harris opened this issue 1 year ago • 0 comments

Describe the bug

Given code like this...

<script>
  let object = $state({ count: 0 });

  function increment() {
    object.count++;
  }
</script>

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

...we generate this output:

function increment(_, object) {
  (() => {
    const $$value = object.count;

    object.count += 1;
    return $$value;
  })();
}

This seems... odd

Reproduction

link

Logs

No response

System Info

next

Severity

annoyance

Rich-Harris avatar Feb 19 '24 17:02 Rich-Harris