Skip to content

Non-updated state treated differently in different places #14280

Closed
@Rich-Harris

Description

@Rich-Harris

Describe the bug

Minor, but given a component like this...

<script>
  let a = $state(1);
  let b = $state(2);
</script>

<p>{a} + {b} = {a + b}</p>

...neither a nor b is turned into state, because they are never updated. But the contents of the <p> are put in an effect anyway:

export default function App($$anchor) {
  let a = 1;
  let b = 2;
  var p = root();
+  var text = $.child(p);

-  p.textContent = `${a ?? ""} + ${b ?? ""} = ${a + b ?? ""}`;
+  $.reset(p);
+  $.template_effect(() => $.set_text(text, `${a ?? ""} + ${b ?? ""} = ${a + b ?? ""}`));
  $.append($$anchor, p);
}

Whatever logic is used for determining whether it's a = 1 or a = $.state(1) should also be used for determining whether to create an effect.

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