Skip to content

Setting class $state property in constructor breaks all tracking #12084

@TGlide

Description

@TGlide

Describe the bug

When setting a class $state property in its constructor, all the reactive tracking seems to break. $effect no longer reacts to its changes, and the value that was set in the constructor is ignored.

Reproduction

Failed to reproduce in REPL, but managed to trigger it on a fairly simple repository: https://github.com/TGlide/society-demos/blob/bug-repro/src/lib/local.svelte.ts

The only workaround I found is to wrap the try catch in a setTimeout.

Logs

No response

System Info

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M2
    Memory: 94.63 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - /usr/local/bin/node
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 8.15.4 - /usr/local/bin/pnpm
    bun: 1.0.29 - ~/.bun/bin/bun
  Browsers:
    Safari: 16.5
  npmPackages:
    svelte: 5.0.0-next.158 => 5.0.0-next.158

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions