-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
Describe the bug
When creating a class with an array state like this:
export class ArrayRef {
value = $state([])
constructor(v: string[] = []) {
this.value = v
}
}The value isn't immediately reactive and requires you to push to it and then it becomes reactive (but doesn't react to the push, only follow on changes afterwards)
However, if you instead initialize it like this:
export class ArrayRef {
value = $state([])
constructor(v: string[] = []) {
this.value.push(...v)
}
}It works as expected
Reproduction
If you spam click the broken way you'll see it eventually updates, where the push works immediately.
Logs
No response
System Info
System:
OS: macOS 14.2
CPU: (12) arm64 Apple M2 Max
Memory: 357.13 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
pnpm: 8.10.2 - ~/Library/pnpm/pnpm
bun: 1.0.3 - ~/.bun/bin/bun
Browsers:
Edge: 120.0.2210.61
Safari: 17.2
npmPackages:
svelte: ^5.0.0-next.1 => 5.0.0-next.22Severity
annoyance
AdrianGonz97
Metadata
Metadata
Assignees
Labels
No labels