-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as not planned
Closed as not planned
Copy link
Description
Describe the bug
When using a store for reactivity, where the store contains an object, svelte 4 allows a reactive block to set a store member based on the value of another store member, without triggering reactivity on the whole store.
In svelte 5, this appears to no longer be possible - assignments to $store.foo trigger reactivity on $store.bar.
Example: the svelte 4 version runs once, the svelte 5 version triggers an infinite loop, when the button is clicked.
<script>
import { writable } from 'svelte/store';
let s = writable({foo: 'foo', bar: null});
$: {
if ($s.foo === 'baz') {
$s.bar = 'some';
} else {
$s.bar = null;
}
}
// $effect(() => {
// if ($s.foo === 'baz') {
// $s.bar = 'some';
// } else {
// $s.bar = null;
// }
// })
</script>
<p>{JSON.stringify($s)}</p>
<button onclick={() => {$s.foo = ($s.foo === 'baz' ? 'foo' : 'baz')}}>modify</button>
I'm not sure how to work around this when dealing with libraries that use stores - I am not in control here, and need to update the value of one store member when another store member changes.
Reproduction
Logs
No response
System Info
System:
OS: macOS 15.1
CPU: (10) arm64 Apple M1 Pro
Memory: 128.16 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.13.1 - ~/.asdf/installs/nodejs/20.13.1/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 10.5.2 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 9.7.0 - ~/.asdf/shims/pnpm
Browsers:
Chrome: 130.0.6723.117
Safari: 18.1
npmPackages:
svelte: ^5.0.0 => 5.2.0Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels