fix: always assign text.nodeValue (#11944)

* fix: always assign text.nodeValue

* guard

* this seems to work
pull/11963/head
Rich Harris 7 months ago committed by GitHub
parent 69d2480f4d
commit 76388d042c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

@ -36,7 +36,7 @@ export function init_operations() {
element_prototype.__e = undefined; element_prototype.__e = undefined;
// @ts-expect-error // @ts-expect-error
Text.prototype.__nodeValue = ' '; Text.prototype.__t = undefined;
if (DEV) { if (DEV) {
// @ts-expect-error // @ts-expect-error

@ -36,22 +36,17 @@ export function set_should_intro(value) {
} }
/** /**
* @param {Element} dom * @param {Element} text
* @param {string} value * @param {string} value
* @returns {void} * @returns {void}
*/ */
export function set_text(dom, value) { export function set_text(text, value) {
// @ts-expect-error need to add __value to patched prototype // @ts-expect-error
const prev_node_value = dom.__nodeValue; const prev = (text.__t ??= text.nodeValue);
const next_node_value = stringify(value);
if (hydrating && dom.nodeValue === next_node_value) { if (prev !== value) {
// In case of hydration don't reset the nodeValue as it's already correct. // @ts-expect-error
// @ts-expect-error need to add __nodeValue to patched prototype text.nodeValue = text.__t = value;
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;
} }
} }

@ -9,7 +9,7 @@ export default test({
Object.defineProperty(p.childNodes[0], 'nodeValue', { Object.defineProperty(p.childNodes[0], 'nodeValue', {
set(value) { 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