Skip to content

Commit 414ce0c

Browse files
committed
fix: reuse DOM nodes inside <template> during hydration
1 parent 88cda26 commit 414ce0c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/diff/children.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export function diffChildren(
5353
isHydrating,
5454
refQueue
5555
) {
56+
if (
57+
parentDom instanceof DocumentFragment &&
58+
newParentVNode.type === 'template' &&
59+
excessDomChildren?.length === 0
60+
) {
61+
excessDomChildren = Array.from(parentDom.childNodes);
62+
}
5663
let i,
5764
/** @type {VNode} */
5865
oldVNode,

test/browser/render.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,4 +2013,11 @@ describe('render()', () => {
20132013
render(<App />, scratch);
20142014
expect(scratch.innerHTML).to.equal('hello world');
20152015
});
2016+
it('should hydrate <template> tags ', () => {
2017+
const App = () => <template><h1>it works</h1></template>
2018+
scratch.innerHTML = `<template><h1>it works</h1></template>`
2019+
2020+
render(<App />, scratch);
2021+
expect(scratch.innerHTML).to.equal(`<template><h1>it works</h1></template>`)
2022+
});
20162023
});

0 commit comments

Comments
 (0)