fix: properly hydrate await in `{@html}` (alternative) (#17528)

* fix: properly hydrate await in `{@html}`

* fix: skip no async

* revert runtime changes

* wrap html blocks in hydration comments

* prettier

---------

Co-authored-by: paoloricciuti <ricciutipaolo@gmail.com>
pull/17517/head
Rich Harris 5 days ago committed by GitHub
parent 7ab62a5878
commit 9b6539a8ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: properly hydrate await in `{@html}`

@ -2,7 +2,7 @@
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '#compiler/builders';
import { create_push } from './shared/utils.js';
import { block_close, block_open, create_push } from './shared/utils.js';
/**
* @param {AST.HtmlTag} node
@ -12,5 +12,15 @@ export function HtmlTag(node, context) {
const expression = /** @type {Expression} */ (context.visit(node.expression));
const call = b.call('$.html', expression);
const has_await = node.metadata.expression.has_await;
if (has_await) {
context.state.template.push(block_open);
}
context.state.template.push(create_push(call, node.metadata.expression, true));
if (has_await) {
context.state.template.push(block_close);
}
}

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
skip_no_async: true,
mode: ['hydrate'],
async test() {}
});

@ -0,0 +1 @@
<div>{@html await Promise.resolve(`<span>Foo</span>`)}</div>
Loading…
Cancel
Save