mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
25 lines
864 B
JavaScript
25 lines
864 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import reactDOMPackageVersion from 'shared/ReactVersion';
|
|
import * as IsomorphicReactPackage from 'react';
|
|
|
|
export function ensureCorrectIsomorphicReactVersion() {
|
|
const isomorphicReactPackageVersion = IsomorphicReactPackage.version;
|
|
if (isomorphicReactPackageVersion !== reactDOMPackageVersion) {
|
|
throw new Error(
|
|
'Incompatible React versions: The "react" and "react-dom" packages must ' +
|
|
'have the exact same version. Instead got:\n' +
|
|
` - react: ${isomorphicReactPackageVersion}\n` +
|
|
` - react-dom: ${reactDOMPackageVersion}\n` +
|
|
'Learn more: https://react.dev/warnings/version-mismatch',
|
|
);
|
|
}
|
|
}
|