Skip to content

onclick callback not optimized inside each loop #17333

@hyunbinseo

Description

@hyunbinseo

Describe the bug

Reference #16414

The 1st onclick callback should be defined once and be reused, but is no longer the case

{#each { length: 2 }, index}
  <button type="button" value={index} onclick={(e) => console.log(e.currentTarget.value)}>
    {index}
  </button>
  <button type="button" onclick={() => console.log(index)}>{index}</button>
{/each}
// was
var on_click = (e) => console.log(e.currentTarget.value);
button.__click = [on_click];

// as-is
$.each(node, 0, () => ({ length: 2 }), $.index, ($$anchor, $$item, index) => {
  var fragment_1 = root_1();
  var button = $.first_child(fragment_1);

  $.set_value(button, index);
  button.__click = (e) => console.log(e.currentTarget.value);

Reproduction

From the issue body

From #16414

Severity

blocking an upgrade

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