Skip to content

Commit bc171a0

Browse files
committed
fix: properly update store values
We need to extend the "don't use `set` on first run" logic to the falsy branch aswell Fixes #12558
1 parent 72f5539 commit bc171a0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/silver-mice-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: properly update store values

packages/svelte/src/internal/client/reactivity/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function store_get(store, store_name, stores) {
2828
entry.store = store ?? null;
2929

3030
if (store == null) {
31-
set(entry.source, undefined);
31+
entry.source.v = undefined; // see synchronous callback comment below
3232
entry.unsubscribe = noop;
3333
} else {
3434
var is_synchronous_callback = true;

packages/svelte/tests/runtime-runes/samples/store-no-mutation-validation/main.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
return () => {};
1010
}
1111
};
12+
let store3 = undefined;
1213
1314
// store signal is updated during reading this, which normally errors, but shouldn't for stores
1415
let name = $derived($store1);
1516
let hello = $derived($store2);
17+
let undefined_value = $derived($store3);
1618
</script>
1719

18-
<h1>{hello} {name}</h1>
20+
<h1>{hello} {name} {undefined_value}</h1>

0 commit comments

Comments
 (0)