Non-updated state treated differently in different places

#14280

Development PR

Issue

Solved
R
Rich-Harris
Nov 12, 2024, 6:29 PM

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

👍 1

Info

Closed at Apr 18, 2025, 3:19 PM
Assignees None
Labels None
Milestone None