Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always assign text.nodeValue #11944

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-cows-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: always assign text.nodeValue
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/dom/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function init_operations() {
element_prototype.__e = undefined;

// @ts-expect-error
Text.prototype.__nodeValue = ' ';
Text.prototype.__t = undefined;

if (DEV) {
// @ts-expect-error
Expand Down
21 changes: 8 additions & 13 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,17 @@ 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) {
// @ts-expect-error
const prev = (text.__t ??= text.nodeValue);

if (prev !== value) {
// @ts-expect-error
text.nodeValue = text.__t = value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default test({

Object.defineProperty(p.childNodes[0], 'nodeValue', {
set(value) {
values.push(value);
values.push('' + value);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
html: `<p>space between</p>`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svelte:options runes />

<p>
{#each ['space', ' ', 'between'] as word}
{word}
{/each}
</p>
Loading