Skip to content

Commit

Permalink
Throw if React and React DOM versions don't match (#29236)
Browse files Browse the repository at this point in the history
Throw an error during module initialization if the version of the
"react-dom" package does not match the version of "react".

We used to be more relaxed about this, because the "react" package
changed so infrequently. However, we now have many more features that
rely on an internal protocol between the two packages, including Hooks,
Float, and the compiler runtime. So it's important that both packages
are versioned in lockstep.

Before this change, a version mismatch would often result in a cryptic
internal error with no indication of the root cause.

Instead, we will now compare the versions during module initialization
and immediately throw an error to catch mistakes as early as possible
and provide a clear error message.

DiffTrain build for commit 681a4aa.
  • Loading branch information
acdlite committed May 28, 2024
1 parent 50be937 commit 63df5e2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ea6e05912aa43a0bbfbee381752caa1817a41a86
681a4aa81022d4053f990d905d6453c73d2ee644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3dbcb35ed104bc31d027dfdf6f5f8da0>>
* @generated SignedSource<<99a2a7f7d6e7d571646aa72aabedfaa0>>
*/

'use strict';
Expand Down Expand Up @@ -26553,7 +26553,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-rc-7e1b1d14';
var ReactVersion = '19.0.0-rc-c2f0c7bb';

/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
Expand Down Expand Up @@ -27467,6 +27467,12 @@ function getInspectorDataForViewAtPoint(findNodeHandle, inspectedView, locationX
}
}

var isomorphicReactPackageVersion = React.version;

if (isomorphicReactPackageVersion !== ReactVersion) {
throw new Error('Incompatible React versions: The "react" and "react-native-renderer" packages must ' + 'have the exact same version. Instead got:\n' + (" - react: " + isomorphicReactPackageVersion + "\n") + (" - react-native-renderer: " + ReactVersion + "\n") + 'Learn more: https://react.dev/warnings/version-mismatch');
}

if (typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog !== 'function') {
throw new Error('Expected ReactFiberErrorDialog.showErrorDialog to be a function.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<8f6bd9d36ed0f004525a1311fbf265d6>>
* @generated SignedSource<<247c643cf9a4130707253f9a40761f49>>
*/

"use strict";
Expand Down Expand Up @@ -10699,6 +10699,13 @@ function traverseOwnerTreeUp(hierarchy, instance) {
"number" === typeof instance.tag &&
traverseOwnerTreeUp(hierarchy, instance);
}
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-rc-28c9760f" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-native-renderer: 19.0.0-rc-28c9760f\nLearn more: https://react.dev/warnings/version-mismatch")
);
if (
"function" !==
typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog
Expand Down Expand Up @@ -10747,7 +10754,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1192 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "19.0.0-rc-20ea0bb8",
version: "19.0.0-rc-28c9760f",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -10790,7 +10797,7 @@ var internals$jscomp$inline_1439 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-rc-20ea0bb8"
reconcilerVersion: "19.0.0-rc-28c9760f"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1440 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<253a44e83fba3348fd4685279485108a>>
* @generated SignedSource<<c874312993c7138b93be21b5b2efadd0>>
*/

"use strict";
Expand Down Expand Up @@ -11406,6 +11406,13 @@ function traverseOwnerTreeUp(hierarchy, instance) {
"number" === typeof instance.tag &&
traverseOwnerTreeUp(hierarchy, instance);
}
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-rc-3983b44c" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-native-renderer: 19.0.0-rc-3983b44c\nLearn more: https://react.dev/warnings/version-mismatch")
);
if (
"function" !==
typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog
Expand Down Expand Up @@ -11454,7 +11461,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1273 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "19.0.0-rc-d745ad21",
version: "19.0.0-rc-3983b44c",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -11510,7 +11517,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-rc-d745ad21"
reconcilerVersion: "19.0.0-rc-3983b44c"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
Expand Down

0 comments on commit 63df5e2

Please sign in to comment.