Skip to content

Commit

Permalink
Merge pull request #2956 from preactjs/hydration-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Jan 24, 2021
2 parents 359ad4f + 5583b46 commit 47c521d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/diff/index.js
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
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>');
});
});

0 comments on commit 47c521d

Please sign in to comment.