Skip to content

Svelte 5: $runes reactivity doesn't work inside setTimeout. #10264

@HighFunctioningSociopathSH

Description

Describe the bug

reactivity is only triggered with assignment inside setTimeout and other methods of updating the $state, for example, the push method of arrays results in no reaction. This seems to happen when using $inspect

Reproduction

  let numbers = $state<number[]>([1, 2, 3]);

  setTimeout(() => {
    // numbers = [1]; This works and $inspect correctly logs the updated value.
    numbers.push(numbers.length + 1) // But this doesn't work and $inspect logs nothing.
  }, 3000);

  $inspect(numbers);

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 7.82 GB / 15.63 GB
  Binaries:
    Node: 18.14.2 - C:\Program Files\nodejs\node.EXE
    npm: 9.7.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (120.0.2210.144)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    svelte: ^5.0.0-next.37 => 5.0.0-next.37

Severity

annoyance

Metadata

Metadata

Assignees

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