Skip to content

Commit

Permalink
support ReactDOM.render(..., document) without crashing (#26129)
Browse files Browse the repository at this point in the history
as reported in #26128 `ReactDOM.render(..., document)` crashed when
`enableHostSingletons` was on. This is because it had a different way of
clearing the container than `createRoot(document)`. I updated the legacy
implementation to share the clearing behavior of `creatRoot` which will
preserve the singleton instances.

I also removed the warning saying not to use `document.body` as a
container

DiffTrain build for [a3152ed](a3152ed)
[View git log for this commit](https://github.com/facebook/react/commits/a3152eda5f89e20f056521855f7fa101ce50e4c3)
  • Loading branch information
gnoff committed Feb 8, 2023
1 parent 9d88d1f commit 3945ca9
Show file tree
Hide file tree
Showing 28 changed files with 932 additions and 971 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
758fc7fde10f49912b18496299506cba30d6029b
a3152eda5f89e20f056521855f7fa101ce50e4c3
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
758fc7fde10f49912b18496299506cba30d6029b
a3152eda5f89e20f056521855f7fa101ce50e4c3
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-classic-758fc7fde-20230207";
var ReactVersion = "18.3.0-www-classic-a3152eda5-20230208";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-758fc7fde-20230207";
var ReactVersion = "18.3.0-www-modern-a3152eda5-20230208";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-758fc7fde-20230207";
exports.version = "18.3.0-www-classic-a3152eda5-20230208";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-758fc7fde-20230207";
exports.version = "18.3.0-www-modern-a3152eda5-20230208";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-758fc7fde-20230207";
exports.version = "18.3.0-www-classic-a3152eda5-20230208";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-758fc7fde-20230207";
exports.version = "18.3.0-www-modern-a3152eda5-20230208";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-758fc7fde-20230207";
var ReactVersion = "18.3.0-www-classic-a3152eda5-20230208";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-modern-758fc7fde-20230207";
var ReactVersion = "18.3.0-www-modern-a3152eda5-20230208";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9845,7 +9845,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-classic-758fc7fde-20230207",
version: "18.3.0-www-classic-a3152eda5-20230208",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1318 = {
Expand Down Expand Up @@ -9876,7 +9876,7 @@ var internals$jscomp$inline_1318 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-758fc7fde-20230207"
reconcilerVersion: "18.3.0-next-a3152eda5-20230208"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1319 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9510,7 +9510,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-758fc7fde-20230207",
version: "18.3.0-www-modern-a3152eda5-20230208",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1309 = {
Expand Down Expand Up @@ -9541,7 +9541,7 @@ var internals$jscomp$inline_1309 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-758fc7fde-20230207"
reconcilerVersion: "18.3.0-next-a3152eda5-20230208"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1310 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
22 changes: 2 additions & 20 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -42695,7 +42695,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-758fc7fde-20230207";
var ReactVersion = "18.3.0-www-classic-a3152eda5-20230208";

function createPortal(
children,
Expand Down Expand Up @@ -43727,20 +43727,6 @@ var topLevelUpdateWarnings;
"and render the new components instead of calling ReactDOM.render."
);
}

if (
container.nodeType === ELEMENT_NODE &&
container.tagName &&
container.tagName.toUpperCase() === "BODY"
) {
error(
"render(): Rendering components directly into document.body is " +
"discouraged, since its children are often manipulated by third-party " +
"scripts and browser extensions. This may lead to subtle " +
"reconciliation issues. Try rendering into a container element created " +
"for your app."
);
}
};
}

Expand Down Expand Up @@ -43800,11 +43786,7 @@ function legacyCreateRootFromDOMContainer(
return root;
} else {
// First clear any existing content.
var rootSibling;

while ((rootSibling = container.lastChild)) {
container.removeChild(rootSibling);
}
clearContainer(container);

if (typeof callback === "function") {
var _originalCallback = callback;
Expand Down
Loading

0 comments on commit 3945ca9

Please sign in to comment.