Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-spies-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: allow `{@html await ...}` and snippets with async content on the server
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ import * as b from '#compiler/builders';
*/
export function HtmlTag(node, context) {
const expression = /** @type {Expression} */ (context.visit(node.expression));
context.state.template.push(b.call('$.html', expression));
const call = b.call('$.html', expression);
context.state.template.push(
node.metadata.expression.has_await
? b.stmt(b.call('$$renderer.push', b.thunk(call, true)))
: call
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** @import { ComponentContext } from '../types.js' */
import { dev } from '../../../../state.js';
import * as b from '#compiler/builders';
import { create_async_block } from './shared/utils.js';

/**
* @param {AST.SnippetBlock} node
Expand All @@ -15,6 +16,10 @@ export function SnippetBlock(node, context) {
/** @type {BlockStatement} */ (context.visit(node.body))
);

if (node.body.metadata.has_await) {
fn.body = b.block([create_async_block(fn.body)]);
}

// @ts-expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
fn.___snippet = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>this should work</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{@html await 'this should work'}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>this should work</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{#snippet foo()}
{@const x = await 'this should work'}
<div>{x}</div>
{/snippet}

{@render foo()}
Loading