mirror of https://github.com/sveltejs/svelte
fix: ensure async initial store value is noticed (#12486)
* fix: ensure async initial store value is noticed fixes #12341 * fix another casepull/12487/head
parent
ea22840e8c
commit
4b8674fe02
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure async initial store value is noticed
|
@ -0,0 +1,10 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client'],
|
||||||
|
async test({ assert, target }) {
|
||||||
|
assert.htmlEqual(target.innerHTML, ' / ');
|
||||||
|
await new Promise((r) => setTimeout(r, 110));
|
||||||
|
assert.htmlEqual(target.innerHTML, '42 / 42');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
function store() {
|
||||||
|
return {
|
||||||
|
subscribe: (cb) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
cb(42);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const value1 = store();
|
||||||
|
const value2 = store();
|
||||||
|
const derivedValue = $derived($value1);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{$value2} / {derivedValue}
|
@ -1,7 +1,18 @@
|
|||||||
<script>
|
<script>
|
||||||
import { writable } from "svelte/store";
|
import { writable } from 'svelte/store';
|
||||||
let store = writable('store');
|
|
||||||
let name = $derived($store); // store signal is updated during reading this, which normally errors, but shouldn't for stores
|
let store1 = writable('store');
|
||||||
|
let store2 = {
|
||||||
|
subscribe: (cb) => {
|
||||||
|
cb('...');
|
||||||
|
cb('Hello');
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// store signal is updated during reading this, which normally errors, but shouldn't for stores
|
||||||
|
let name = $derived($store1);
|
||||||
|
let hello = $derived($store2);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>Hello {name}</h1>
|
<h1>{hello} {name}</h1>
|
||||||
|
Loading…
Reference in new issue