Skip to content

svelte 5: unnecessary code generated for updates #10546

Closed
@Rich-Harris

Description

@Rich-Harris

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

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