-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as duplicate of#16199
Description
Describe the bug
No reactivity when accessing $state runed inside class
Reproduction
https://svelte.dev/playground/1fbdb18c49fd4caf8c1182cfb5fa673a?version=5.34.7
<script>
import { Store } from './store.svelte';
const store = new Store();
// when the following line is uncommented it works
// let whatever = $state()
</script>
<div>{store.count}</div>
<button onclick={() => store.increment()}>Update</button>
state.svelte.ts
export class Store {
count = $state(0);
increment() {
this.count++;
console.log(this.count)
}
}
Logs
System Info
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M1
Memory: 276.39 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 11.3.0 - ~/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.11.1 - /opt/homebrew/bin/pnpm
bun: 1.2.4 - ~/.bun/bin/bun
Watchman: 2025.04.28.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 137.1.79.126
Chrome: 137.0.7151.120
Safari: 18.5
npmPackages:
svelte: ^5.27.0 => 5.34.7Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels