Skip to content

$state rune inside class isn't reactive  #16225

@dinisrosas

Description

@dinisrosas

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.7

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