Skip to content

Commit 0215c83

Browse files
committed
Allow Document as container for createRoot
previously rendering into Document was broken and only hydration worked because React did not properly deal with the documentElement and would error in a broken state if used that way. With the previous commit addressing this limitation this change re-adds Document as a valid container for createRoot. It should be noted that if you use document with createRoot it will drop anything a 3rd party scripts adds the page before rendering for the first time.
1 parent fd06131 commit 0215c83

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

packages/react-dom/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from './';
2424

2525
export function createRoot(
26-
container: Element | DocumentFragment,
26+
container: Element | Document | DocumentFragment,
2727
options?: CreateRootOptions,
2828
): RootType {
2929
if (__DEV__) {

packages/react-dom/src/client/ReactDOM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Internals = {
148148
};
149149

150150
function createRoot(
151-
container: Element | DocumentFragment,
151+
container: Element | Document | DocumentFragment,
152152
options?: CreateRootOptions,
153153
): RootType {
154154
if (__DEV__) {

packages/react-dom/src/client/ReactDOMRoot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ReactDOMHydrationRoot.prototype.unmount = ReactDOMRoot.prototype.unmount = funct
164164
};
165165

166166
export function createRoot(
167-
container: Element | DocumentFragment,
167+
container: Element | Document | DocumentFragment,
168168
options?: CreateRootOptions,
169169
): RootType {
170170
if (!isValidContainer(container)) {

0 commit comments

Comments
 (0)