svelte: derived value is not updating correctly

Describe the bug

the derived value depends on a class field of a newly created class. when this derived value has a fallback value (like “v || ‘-’”) it doesnt update correctly. removing the fallback seems to fix the issue.

Reproduction

https://svelte.dev/playground/dec1b43d47eb4c3aa729291f91ab8a39?version=5.28.2

Logs


System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 21.19 GB / 31.91 GB
  Binaries:
    Node: 22.12.0 - ~\AppData\Local\fnm_multishells\15692_1745479128899\node.EXE
    Yarn: 1.22.22 - ~\AppData\Local\fnm_multishells\15692_1745479128899\yarn.CMD
    npm: 11.3.0 - ~\AppData\Local\fnm_multishells\15692_1745479128899\npm.CMD
    pnpm: 10.7.0 - ~\AppData\Local\fnm_multishells\15692_1745479128899\pnpm.CMD
  Browsers:
    Edge: Chromium (133.0.3065.82)
    Internet Explorer: 11.0.22621.3527

Severity

annoyance

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (13 by maintainers)

Commits related to this issue

Most upvoted comments

So a bit more exploration and the problem is that skip_reaction is true when running the derived because it’s UNOWNED there’s no active_reaction before and this line to check there was no parent was removed in #15232

Adding the line back obviously is a no-go as it make that test fail. I’ll try to figure out if there’s another solution but it’s getting late lol

Weird that it seems to work when you replace || with ??

The reason why this works is because this.c1?.v || '-' actually returns twice the same value when v is 0 and that’s the root issue.

Basically: the value of the derived is - before c1 is defined in the set function and it’s also - after c1 is defined…this means that the template_effect that updates the text in the dom is not executed and it never register a dependency on v so when it changes it doesn’t re-execute.

Gonna explore this a bit more but it’s hard to wrap your head around.