Skip to content

Commit cf35a22

Browse files
Ocean-OSdummdidumm
andauthored
fix: allow {@html await ...} and async snippets on the server (#16817)
Fixes #16816 Fixes #16811 --------- Co-authored-by: Simon Holthausen <[email protected]> Co-authored-by: Simon H <[email protected]>
1 parent 3c694ce commit cf35a22

File tree

7 files changed

+25
-1
lines changed

7 files changed

+25
-1
lines changed

.changeset/long-spies-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: allow `{@html await ...}` and snippets with async content on the server

packages/svelte/src/compiler/phases/3-transform/server/visitors/HtmlTag.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ import * as b from '#compiler/builders';
99
*/
1010
export function HtmlTag(node, context) {
1111
const expression = /** @type {Expression} */ (context.visit(node.expression));
12-
context.state.template.push(b.call('$.html', expression));
12+
const call = b.call('$.html', expression);
13+
context.state.template.push(
14+
node.metadata.expression.has_await
15+
? b.stmt(b.call('$$renderer.push', b.thunk(call, true)))
16+
: call
17+
);
1318
}

packages/svelte/src/compiler/phases/3-transform/server/visitors/SnippetBlock.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/** @import { ComponentContext } from '../types.js' */
44
import { dev } from '../../../../state.js';
55
import * as b from '#compiler/builders';
6+
import { create_async_block } from './shared/utils.js';
67

78
/**
89
* @param {AST.SnippetBlock} node
@@ -15,6 +16,10 @@ export function SnippetBlock(node, context) {
1516
/** @type {BlockStatement} */ (context.visit(node.body))
1617
);
1718

19+
if (node.body.metadata.has_await) {
20+
fn.body = b.block([create_async_block(fn.body)]);
21+
}
22+
1823
// @ts-expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
1924
fn.___snippet = true;
2025

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>this should work</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>{@html await 'this should work'}</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>this should work</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{#snippet foo()}
2+
{@const x = await 'this should work'}
3+
<div>{x}</div>
4+
{/snippet}
5+
6+
{@render foo()}

0 commit comments

Comments
 (0)