mirror of https://github.com/sveltejs/svelte
fix: update `$effect.pending()` immediately after a batch is removed (#16382)
* WIP sync effect pending updates * fix * changeset * fix * add test * inline * unusedpull/16392/head
parent
3fa3dd78a1
commit
e01bd97bef
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: update `$effect.pending()` immediately after a batch is removed
|
@ -0,0 +1,81 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [increment, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
shift.click();
|
||||||
|
shift.click();
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 3</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 2</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>0</p>
|
||||||
|
<p>pending: 1</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift</button>
|
||||||
|
<p>1</p>
|
||||||
|
<p>1</p>
|
||||||
|
<p>1</p>
|
||||||
|
<p>pending: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
let value = $state(0);
|
||||||
|
let deferreds = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
const deferred = Promise.withResolvers();
|
||||||
|
deferreds.push({ value, deferred });
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shift() {
|
||||||
|
const d = deferreds.shift();
|
||||||
|
d?.deferred.resolve(d.value);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => value++}>increment</button>
|
||||||
|
<button onclick={() => shift()}>shift</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
<p>{await push(value)}</p>
|
||||||
|
|
||||||
|
<p>pending: {$effect.pending()}</p>
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>loading...</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue