fix: handle compiled `nodeValue`/`textContent`

pull/18058/head
paoloricciuti 4 months ago
parent ecffd81c22
commit e86da84c79

@ -346,9 +346,25 @@ export function RegularElement(node, context) {
const empty_string = value.type === 'Literal' && value.value === '';
if (!empty_string) {
child_state.init.push(
b.stmt(b.assignment('=', b.member(context.state.node, 'textContent'), value))
);
if (context.state.options.customRenderer) {
// custom renderers need to use the method to invoke the renderer
context.state.template.push_text([
{
type: 'Text',
data: '',
raw: '',
start: -1,
end: -1
}
]);
const text = context.state.scope.generate('text');
context.state.init.push(b.var(text, b.call('$.child', node_id)));
context.state.init.push(b.stmt(b.call('$.set_text', b.id(text), value)));
} else {
child_state.init.push(
b.stmt(b.assignment('=', b.member(context.state.node, 'textContent'), value))
);
}
}
} else if (is_customizable_select_element(node)) {
// For <option>, <optgroup>, or <select> elements with rich content, we need to branch based on browser support.

@ -83,7 +83,12 @@ export function process_children(nodes, initial, is_element, context) {
if (has_state && !within_bound_contenteditable) {
context.state.update.push(update);
} else {
context.state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value)));
if (context.state.options.customRenderer) {
// custom renderers need to use the method to invoke the renderer
context.state.init.push(update);
} else {
context.state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value)));
}
}
}

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: '<p>hello world</p>'
});

@ -0,0 +1,5 @@
<script>
let name = $state("world");
</script>
<p>hello {name}</p>

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: 'hello world'
});

@ -0,0 +1,5 @@
<script>
let name = $state("world");
</script>
hello {name}
Loading…
Cancel
Save