Merge branch 'main' into svelte-custom-renderer

svelte-custom-renderer
Paolo Ricciuti 1 day ago committed by GitHub
commit 3e657cd542
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: resolve stale deriveds with latest value

@ -232,7 +232,7 @@ export function async_derived(fn, label, location) {
for (const [b, d] of deferreds) {
deferreds.delete(b);
if (b === batch) break;
d.reject(STALE_REACTION);
d.resolve(value);
}
if (DEV && location !== undefined) {

@ -0,0 +1,29 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target }) {
await tick();
const [increment, pop] = target.querySelectorAll('button');
increment.click();
await tick();
increment.click();
await tick();
assert.htmlEqual(
target.innerHTML,
`<button>increment</button><button>pop</button><p>0 0 0</p>`
);
pop.click();
await tick();
assert.htmlEqual(
target.innerHTML,
`<button>increment</button><button>pop</button><p>2 2 1</p>`
);
}
});

@ -0,0 +1,22 @@
<script>
let count = $state(0);
let other = $state(0);
const queue = [];
function push(v) {
if (v === 0) return v;
return new Promise((fulfil) => {
queue.push(() => fulfil(v));
});
}
</script>
<button onclick={() => {
if (count === 0) other++;
count++;
}}>increment</button>
<button onclick={() => queue.pop()?.()}>pop</button>
<p>{await push(count)} {count} {other}</p>
Loading…
Cancel
Save