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 1 commit
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
3 changes: 0 additions & 3 deletions packages/svelte/src/internal/client/dom/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you removing skipping during hydration because reading nodeValue to eventually skip if eventually more expensive than just set the value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's just nothing to do differently in the hydration case any more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's just nothing to do differently in the hydration case any more

Wouldn't be possible to skip the assignment since the value is already there from SSR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could have changed

}

/**
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