-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
🦋 Changeset detectedLatest commit: 699caa6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dom.__nodeValue = next_node_value; | ||
} | ||
export function set_text(text, value) { | ||
text.nodeValue = value; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could have changed
This results in DOM mutations even when the content is the same unfortunately |
fixed with a |
This is slower than what we have on main: I wrapped |
My proposed fix is: export function set_text(dom, value) {
// @ts-expect-error need to add __value to patched prototype
const prev_node_value = dom.__nodeValue ??= dom.nodeValue;
const next_node_value = stringify(value);
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;
}
} Text.prototype.__nodeValue = undefined; |
Tweaked the benchmark to use |
@Rich-Harris If you put in |
Here's another benchmark that shows it even clearer. |
Even if it's a tiny bit slower, does that really matter? It's roughly 1 milisecond judging from the benchmark, and that's for 4000 text nodes which is a lot. |
I found implicit coercion to be faster than explicit. Just pushed a tweak |
@dummdidumm My last comment shows that actually, pretty well too. Update: Rich just patched it, so the overhead from reading |
alternative to #11937
Closes #11932
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint