Skip to content

Commit 4b7e231

Browse files
Support the template tag (#4639)
* Support the template tag * Add test * Types * chore: simplify template check * chore: instantiate template tag in test --------- Co-authored-by: Marvin Hagemeister <[email protected]>
1 parent cad1daf commit 4b7e231

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/diff/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ function diffElementNodes(
525525
if (oldHtml) dom.innerHTML = '';
526526

527527
diffChildren(
528-
dom,
528+
// @ts-expect-error
529+
newVNode.type === 'template' ? dom.content : dom,
529530
isArray(newChildren) ? newChildren : [newChildren],
530531
newVNode,
531532
oldVNode,

test/browser/render.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ describe('render()', () => {
9292
});
9393
}
9494

95+
it('should support the <template> tag', () => {
96+
function App() {
97+
return (
98+
<template>
99+
<h1>it works</h1>
100+
</template>
101+
);
102+
}
103+
104+
render(<App />, scratch);
105+
const clone = scratch.firstChild.content.cloneNode(true);
106+
expect(clone.firstChild.outerHTML).to.eql('<h1>it works</h1>');
107+
});
108+
95109
it('should not render when detecting JSON-injection', () => {
96110
const vnode = JSON.parse('{"type":"span","children":"Malicious"}');
97111
render(vnode, scratch);

0 commit comments

Comments
 (0)