Skip to content

Commit 76388d0

Browse files
authored
fix: always assign text.nodeValue (#11944)
* fix: always assign text.nodeValue * guard * this seems to work
1 parent 69d2480 commit 76388d0

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

.changeset/twelve-cows-learn.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: always assign text.nodeValue

packages/svelte/src/internal/client/dom/operations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function init_operations() {
3636
element_prototype.__e = undefined;
3737

3838
// @ts-expect-error
39-
Text.prototype.__nodeValue = ' ';
39+
Text.prototype.__t = undefined;
4040

4141
if (DEV) {
4242
// @ts-expect-error

packages/svelte/src/internal/client/render.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,17 @@ export function set_should_intro(value) {
3636
}
3737

3838
/**
39-
* @param {Element} dom
39+
* @param {Element} text
4040
* @param {string} value
4141
* @returns {void}
4242
*/
43-
export function set_text(dom, value) {
44-
// @ts-expect-error need to add __value to patched prototype
45-
const prev_node_value = dom.__nodeValue;
46-
const next_node_value = stringify(value);
47-
if (hydrating && dom.nodeValue === next_node_value) {
48-
// In case of hydration don't reset the nodeValue as it's already correct.
49-
// @ts-expect-error need to add __nodeValue to patched prototype
50-
dom.__nodeValue = next_node_value;
51-
} else if (prev_node_value !== next_node_value) {
52-
dom.nodeValue = next_node_value;
53-
// @ts-expect-error need to add __className to patched prototype
54-
dom.__nodeValue = next_node_value;
43+
export function set_text(text, value) {
44+
// @ts-expect-error
45+
const prev = (text.__t ??= text.nodeValue);
46+
47+
if (prev !== value) {
48+
// @ts-expect-error
49+
text.nodeValue = text.__t = value;
5550
}
5651
}
5752

packages/svelte/tests/runtime-legacy/samples/bindings-coalesced/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default test({
99

1010
Object.defineProperty(p.childNodes[0], 'nodeValue', {
1111
set(value) {
12-
values.push(value);
12+
values.push('' + value);
1313
}
1414
});
1515

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
html: `<p>space between</p>`
6+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<svelte:options runes />
2+
3+
<p>
4+
{#each ['space', ' ', 'between'] as word}
5+
{word}
6+
{/each}
7+
</p>

0 commit comments

Comments
 (0)