0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00
This commit is contained in:
bluwy 2025-01-07 00:31:59 +08:00
parent b46f764aa5
commit a0cdd02829
2 changed files with 8 additions and 3 deletions

View file

@ -1,10 +1,16 @@
import { version as ReactVersion } from 'react-dom';
import { createRequire } from 'node:module';
export type SupportedReactVersion = keyof typeof versionsConfig;
export type ReactVersionConfig = (typeof versionsConfig)[SupportedReactVersion];
export function getReactMajorVersion(): number {
const matches = /\d+\./.exec(ReactVersion);
// NOTE: Do not import `version` from `react-dom` because in 2025 React 19 still relies on
// `process.env.NODE_ENV` to determine export dev or prod code, and if we import `react-dom`
// too early (e.g. in the astro config) before we set `process.env.NODE_ENV`, it may reference
// the dev code, and then `react` will reference the prod code, and we get a mismatch of
// `TypeError: dispatcher.getOwner is not a function`
const pkgJson = createRequire(import.meta.url)('react-dom/package.json');
const matches = /\d+\./.exec(pkgJson.version);
if (!matches) {
return NaN;
}

1
pnpm-lock.yaml generated
View file

@ -9003,7 +9003,6 @@ packages:
libsql@0.4.5:
resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==}
cpu: [x64, arm64, wasm32]
os: [darwin, linux, win32]
lilconfig@3.1.3: