Merge branch 'main' into svelte-custom-renderer

pull/18317/head
Paolo Ricciuti 2 months ago committed by GitHub
commit 203fe2e62e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: propagate async `@const` blockers through closure references so template expressions like `{(() => host)()}` correctly wait for the awaited value

@ -52,7 +52,7 @@ export class Memoizer {
* @param {ExpressionMetadata} metadata
*/
check_blockers(metadata) {
for (const binding of metadata.dependencies) {
for (const binding of metadata.references) {
if (binding.blocker) {
this.#blockers.add(binding.blocker);
}

@ -102,8 +102,8 @@ export class ExpressionMetadata {
if (!this.#blockers) {
this.#blockers = new Set();
for (const d of this.dependencies) {
if (d.blocker) this.#blockers.add(d.blocker);
for (const r of this.references) {
if (r.blocker) this.#blockers.add(r.blocker);
}
}

@ -0,0 +1,14 @@
import { tick } from 'svelte';
import { test } from '../../test';
// Tests that an IIFE referencing an `await` @const inside an {#each} block
// correctly registers the async dependency so the template waits for the
// resolved value instead of rendering with `undefined`.
export default test({
mode: ['client', 'hydrate', 'async-server'],
ssrHtml: '<p>example.com</p>',
async test({ assert, target }) {
await tick();
assert.htmlEqual(target.innerHTML, '<p>example.com</p>');
}
});

@ -0,0 +1,10 @@
<script>
async function get_host() {
return 'example.com';
}
</script>
{#each { length: 1 } as nothing}
{@const host = await get_host()}
<p>{(() => host)()}</p>
{/each}
Loading…
Cancel
Save