Prevent deopts from modifying exports object in stable builds (#14309)
Dan Abramov committed
Nov 23, 2018 at 14:10 UTC
7475120ce7bdeb7a5666d64c636efb1f4a951b9a
2 files changed
+12
-5
packages/react-dom/src/client/ReactDOM.js
+2
-2
@@ -770,6 +770,7 @@ const ReactDOM: Object = {
770
771
flushSync: flushSync,
772
773
+ unstable_createRoot: createRoot,
774
unstable_flushControlled: flushControlled,
775
776
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
@@ -810,8 +811,7 @@ function createRoot(container: DOMContainer, options?: RootOptions): ReactRoot {
811
812
if (enableStableConcurrentModeAPIs) {
813
ReactDOM.createRoot = createRoot;
813
-} else {
814
- ReactDOM.unstable_createRoot = createRoot;
814
+ ReactDOM.unstable_createRoot = undefined;
815
}
816
817
const foundDevTools = injectIntoDevTools({
packages/react/src/React.js
+10
-3
@@ -77,15 +77,22 @@ const React = {
77
78
version: ReactVersion,
79
80
+ unstable_ConcurrentMode: REACT_CONCURRENT_MODE_TYPE,
81
+ unstable_Profiler: REACT_PROFILER_TYPE,
82
+
83
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals,
84
};
85
86
+// Note: some APIs are added with feature flags.
87
+// Make sure that stable builds for open source
88
+// don't modify the React object to avoid deopts.
89
+// Also let's not expose their names in stable builds.
90
+
91
if (enableStableConcurrentModeAPIs) {
92
React.ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
93
React.Profiler = REACT_PROFILER_TYPE;
86
-} else {
87
- React.unstable_ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
88
- React.unstable_Profiler = REACT_PROFILER_TYPE;
94
+ React.unstable_ConcurrentMode = undefined;
95
+ React.unstable_Profiler = undefined;
96
}
97
98
if (enableHooks) {