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

Zero Mutation Text Hydration #2290

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 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
12 changes: 11 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ function diffElementNodes(

if (dom == null) {
if (newVNode.type === null) {
// During hydration, only the first Text node is attached.
// Subsequent updates will trigger splitting up into separate nodes.
// See https://github.com/preactjs/preact/wiki/Hydration-Design-Documentation
if (isHydrating && excessDomChildren != null) return null;

return document.createTextNode(newProps);
}

Expand All @@ -310,7 +315,12 @@ function diffElementNodes(
excessDomChildren[excessDomChildren.indexOf(dom)] = null;
}

if (oldProps !== newProps && dom.data != newProps) {
// Text mutations during hydration are ignored.
// See https://github.com/preactjs/preact/wiki/Hydration-Design-Documentation
if (isHydrating && excessDomChildren != null) {
newVNode.props = dom.data;
}
else if (oldProps !== newProps) {
dom.data = newProps;
}
} else if (newVNode !== oldVNode) {
Expand Down