mirror of https://github.com/sveltejs/svelte
fix: block declaration tags on async values read inside closures (#18533)
Fixes #18469 Declaration tags collect blockers from `metadata.expression.dependencies`, which only sees eager reads, so a `$derived` reading an async declaration inside a closure gets no blocker and evaluates while the value is still `undefined`. Align with template expressions which already collect blockers from `references` --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/18722/head
parent
aadc97ce1b
commit
4d5139552d
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: block declaration tags and `{@const}` on async values read inside closures
|
||||
@ -0,0 +1,10 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// #18469 — a @const in a nested snippet reading an async declaration through a closure must block on it
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, '<p>true</p> <p>false</p>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
async function getValue() {
|
||||
return new Set(['a', 'b', 'c']);
|
||||
}
|
||||
|
||||
const value = await getValue();
|
||||
</script>
|
||||
|
||||
{#each [['a', 'b'], ['a', 'x']] as keys}
|
||||
{@const all_present = keys.every((k) => value.has(k))}
|
||||
<p>{all_present}</p>
|
||||
{/each}
|
||||
@ -0,0 +1,11 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// #18469 — a sync $derived in a nested snippet reading an async declaration through a closure must block on it
|
||||
export default test({
|
||||
ssrHtml: '<p>true</p> <p>false</p>',
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, '<p>true</p> <p>false</p>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
async function getValue() {
|
||||
return new Set(['a', 'b', 'c']);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet outer()}
|
||||
{const value = $derived(await getValue())}
|
||||
{#snippet inner(keys)}
|
||||
{const all_present = $derived(keys.every((k) => value.has(k)))}
|
||||
<p>{all_present}</p>
|
||||
{/snippet}
|
||||
{@render inner(['a', 'b'])}
|
||||
{@render inner(['a', 'x'])}
|
||||
{/snippet}
|
||||
|
||||
{@render outer()}
|
||||
Loading…
Reference in new issue