Skip to content
Open
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
16 changes: 9 additions & 7 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import { slice } from './util';
* existing DOM tree rooted at `replaceNode`
*/
export function render(vnode, parentDom, replaceNode) {
// https://github.com/preactjs/preact/issues/3794
if (parentDom == document) {
parentDom = document.documentElement;
}
const documentElement = document.documentElement,
isDocumentRender = parentDom == document;

if (options._root) options._root(vnode, parentDom);

Expand All @@ -40,7 +38,7 @@ export function render(vnode, parentDom, replaceNode) {
let commitQueue = [],
refQueue = [];
diff(
parentDom,
isDocumentRender ? documentElement : parentDom,
// Determine the new vnode tree and store it on the DOM element on
// our custom `_children` property.
vnode,
Expand All @@ -52,14 +50,18 @@ export function render(vnode, parentDom, replaceNode) {
: oldVNode
? NULL
: parentDom.firstChild
? slice.call(parentDom.childNodes)
? isDocumentRender
? [documentElement]
: slice.call(parentDom.childNodes)
: NULL,
commitQueue,
!isHydrating && replaceNode
? replaceNode
: oldVNode
? oldVNode._dom
: parentDom.firstChild,
: isDocumentRender
? documentElement
: parentDom.firstChild,
isHydrating,
refQueue
);
Expand Down
4 changes: 2 additions & 2 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,14 +1970,14 @@ describe('render()', () => {
it('should work with document', () => {
document.textContent = '';
const App = () => (
<Fragment>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Test</p>
</body>
</Fragment>
</html>
);
render(<App />, document);
expect(document.documentElement.innerHTML.trim()).to.equal(
Expand Down
Loading