fix: always assign text.nodeValue

pull/11944/head
Rich Harris 2 years ago
parent aadf629580
commit 2e375b43b3

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: always assign text.nodeValue

@ -34,9 +34,6 @@ export function init_operations() {
// @ts-expect-error
element_prototype.__e = undefined;
// @ts-expect-error
Text.prototype.__nodeValue = ' ';
if (DEV) {
// @ts-expect-error
element_prototype.__svelte_meta = null;

@ -36,23 +36,12 @@ export function set_should_intro(value) {
}
/**
* @param {Element} dom
* @param {Element} text
* @param {string} value
* @returns {void}
*/
export function set_text(dom, value) {
// @ts-expect-error need to add __value to patched prototype
const prev_node_value = dom.__nodeValue;
const next_node_value = stringify(value);
if (hydrating && dom.nodeValue === next_node_value) {
// In case of hydration don't reset the nodeValue as it's already correct.
// @ts-expect-error need to add __nodeValue to patched prototype
dom.__nodeValue = next_node_value;
} else if (prev_node_value !== next_node_value) {
dom.nodeValue = next_node_value;
// @ts-expect-error need to add __className to patched prototype
dom.__nodeValue = next_node_value;
}
export function set_text(text, value) {
text.nodeValue = value;
}
/**

@ -9,7 +9,7 @@ export default test({
Object.defineProperty(p.childNodes[0], 'nodeValue', {
set(value) {
values.push(value);
values.push('' + value);
}
});

@ -0,0 +1,6 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: `<p>space between</p>`
});

@ -0,0 +1,7 @@
<svelte:options runes />
<p>
{#each ['space', ' ', 'between'] as word}
{word}
{/each}
</p>
Loading…
Cancel
Save