Skip to content

Difference in Behavior Between writable(...) and $state(...) with Classes #14411

@Tb1281

Description

@Tb1281

Describe the bug

It seems that writable(...) and $state(...) behave differently when used with class instances.

For example, given the following class:

class Test {
test = 0;
}

• Using writable(new Test()) makes it reactive.
• However, using $state(new Test()) does not make it reactive.

This behavior is described in the migration guide, but I wanted to confirm if this is the intended design.

If it is, should we always use writable(...) for handling reactivity with class instances?

Playground example for reference:
https://svelte.dev/playground/74b96807cf2a405984f202fe1c8a01cb?version=5.2.7

Reproduction

https://svelte.dev/playground/74b96807cf2a405984f202fe1c8a01cb?version=5.2.7

Logs

No response

System Info

All

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