mirror of https://github.com/sveltejs/svelte
fix: handle asnyc updates within pending boundary (#17873)
When an async value is updated inside the boundary while the pending snippet is shown, we previously didn't notice that update and instead showed an outdated value once it resolved. This fixes that by rejecting all deferreds inside an async_derived while the pending snippet is shown. --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17877/head
parent
0206a2019e
commit
2deebdea8f
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: handle asnyc updates within pending boundary
|
||||
@ -0,0 +1,51 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
const [shift, increment] = target.querySelectorAll('button');
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>shift</button>
|
||||
<button>increment</button>
|
||||
loading
|
||||
`
|
||||
);
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>shift</button>
|
||||
<button>increment</button>
|
||||
loading
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>shift</button>
|
||||
<button>increment</button>
|
||||
loading
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>shift</button>
|
||||
<button>increment</button>
|
||||
1
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
let queue = [];
|
||||
|
||||
function push(value) {
|
||||
const deferred = Promise.withResolvers();
|
||||
queue.push(() => deferred.resolve(value));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
let count = $state(0);
|
||||
</script>
|
||||
|
||||
<button onclick={() => queue.shift()()}>shift</button>
|
||||
<button onclick={() => count++}>increment</button>
|
||||
|
||||
<svelte:boundary>
|
||||
{await push(count)}
|
||||
{#snippet pending()}loading{/snippet}
|
||||
</svelte:boundary>
|
||||
Loading…
Reference in new issue