Skip to content

Commit

Permalink
Support the template tag (#4639)
Browse files Browse the repository at this point in the history
* Support the template tag

* Add test

* Types

* chore: simplify template check

* chore: instantiate template tag in test

---------

Co-authored-by: Marvin Hagemeister <[email protected]>
  • Loading branch information
JoviDeCroock and marvinhagemeister authored Jan 19, 2025
1 parent cad1daf commit 4b7e231
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ function diffElementNodes(
if (oldHtml) dom.innerHTML = '';

diffChildren(
dom,
// @ts-expect-error
newVNode.type === 'template' ? dom.content : dom,
isArray(newChildren) ? newChildren : [newChildren],
newVNode,
oldVNode,
Expand Down
14 changes: 14 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ describe('render()', () => {
});
}

it('should support the <template> tag', () => {
function App() {
return (
<template>
<h1>it works</h1>
</template>
);
}

render(<App />, scratch);
const clone = scratch.firstChild.content.cloneNode(true);
expect(clone.firstChild.outerHTML).to.eql('<h1>it works</h1>');
});

it('should not render when detecting JSON-injection', () => {
const vnode = JSON.parse('{"type":"span","children":"Malicious"}');
render(vnode, scratch);
Expand Down

0 comments on commit 4b7e231

Please sign in to comment.