mirror of https://github.com/sveltejs/svelte
fix: correctly reschedule deferred effects when reviving a batch after async work (#17332)
* WIP * test * fix: correctly reschedule deferred effects when reviving a batch after async workpull/17343/head
parent
4e6104a939
commit
b268ccbf44
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: correctly reschedule deferred effects when reviving a batch after async work
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
<script>
|
||||||
|
$effect(() => {})
|
||||||
|
</script>
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [a, b, resolve] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
a.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
b.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>a (true)</button>
|
||||||
|
<button>b (true)</button>
|
||||||
|
<button>resolve</button>
|
||||||
|
42
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let a = $state(false);
|
||||||
|
let b = $state(false);
|
||||||
|
|
||||||
|
let deferred = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
const d = Promise.withResolvers();
|
||||||
|
deferred.push(() => d.resolve(value))
|
||||||
|
return d.promise;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => a = !a}>a ({a})</button>
|
||||||
|
<button onclick={() => b = !b}>b ({b})</button>
|
||||||
|
<button onclick={() => deferred.shift()()}>resolve</button>
|
||||||
|
|
||||||
|
{#if a}
|
||||||
|
{await push(42)}
|
||||||
|
<Child />
|
||||||
|
{/if}
|
||||||
Loading…
Reference in new issue