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 HTML comments breaking hydration #2956

Merged
merged 2 commits into from
Jan 24, 2021
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
8 changes: 7 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ function diffElementNodes(
//
// Note: This takes advantage of Text nodes having `.localName=undefined`,
// which is loosely equal to Text VNodes' `.type=null`. Elements use string equality.
if (child != null && (dom == child || child.localName == nodeType)) {
if (
child != null &&
((nodeType === null
? child.nodeType === 3
: child.localName === nodeType) ||
dom == child)
) {
dom = child;
excessDomChildren[i] = null;
break;
Expand Down
6 changes: 6 additions & 0 deletions test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,10 @@ describe('hydrate()', () => {
'<p class="hi">hello baz</p><p class="hi">hello bar</p>'
);
});

it('should skip comment nodes', () => {
scratch.innerHTML = '<p>hello <!-- c -->foo</p>';
hydrate(<p>hello {'foo'}</p>, scratch);
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
});
});