fix: properly update store values (#12562)

We need to extend the "don't use `set` on first run" logic to the falsy branch aswell

Fixes #12558
pull/12564/head
Simon H 1 year ago committed by GitHub
parent 72f5539f51
commit e2b75d1a6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: properly update store values

@ -28,7 +28,7 @@ export function store_get(store, store_name, stores) {
entry.store = store ?? null; entry.store = store ?? null;
if (store == null) { if (store == null) {
set(entry.source, undefined); entry.source.v = undefined; // see synchronous callback comment below
entry.unsubscribe = noop; entry.unsubscribe = noop;
} else { } else {
var is_synchronous_callback = true; var is_synchronous_callback = true;

@ -9,10 +9,12 @@
return () => {}; return () => {};
} }
}; };
let store3 = undefined;
// store signal is updated during reading this, which normally errors, but shouldn't for stores // store signal is updated during reading this, which normally errors, but shouldn't for stores
let name = $derived($store1); let name = $derived($store1);
let hello = $derived($store2); let hello = $derived($store2);
let undefined_value = $derived($store3);
</script> </script>
<h1>{hello} {name}</h1> <h1>{hello} {name} {undefined_value}</h1>

Loading…
Cancel
Save