Skip to content

Svelte 5: accessing state members from a class constructor bypasses reactivity #9407

@robertadamsonsmith

Description

@robertadamsonsmith

Describe the bug

When state member variables are initialised from a class constructor, they bypass reactivity logic as an optimisation (presumably).

However, this means that if other code is added directly to the constructor that asynchronously modifies state member variables (through this.), it does so in a way that bypasses reactivity logic.

This can by avoided by moving all logic to a member function in which reactivity logic is not bypassed, but it is not expected that this is required.

Either a fix to allow the expected behaviour, a runtime warning, or documenting the behaviour would be helpful.

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACpVR22qDQBD9lem2UAXR0EcTUwKlX1DIQ7eQZR2bpeuuOGNCEf-966apee2LyzlzLsM4isZYJFG-j8KpFkUpdl0nMsHf3QzohJYxYPJDr2dmQ7o3HW-lk6ytIoKdVX0L40xIbowzdMQaKnggVoxJoyxhur6MtXfE_aDZ9wmbFtPoiyPJRfHikdwjw9n3XxmQcRpB-7YLO9ZgHHs48NFQfn-tyU_KDni4JhDyW0j1AydJWm2j9maj0IwZxN71be0-1NECoy24OPmTBn66PEWxTMYr9d_maIqB8WORQcUrVuDwfLlo8rRarWb1plhO7saoW6KfQYrXX3AnBZQB75Vh4z7zPJdiCv-u9bVpDNainNeYPqYfoTtYofYBAAA=

Logs

No response

System Info

Svelte 5 Preview REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions