-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support react 19 #12395
feat: support react 19 #12395
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Walkthrough这些变更主要集中在改进 React 版本检测逻辑。通过解析版本字符串并比较主版本号,代码更加健壮和易于维护。这些调整确保了在不同版本的 React 环境中,功能能正确地执行。 Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Size Change: +38 B (0%) Total Size: 9.9 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/preset-umi/src/features/configPlugins/configPlugins.ts (1 hunks)
- packages/preset-umi/src/features/mpa/mpa.ts (1 hunks)
Additional comments not posted (2)
packages/preset-umi/src/features/configPlugins/configPlugins.ts (1)
33-33
: 逻辑正确,符合预期。packages/preset-umi/src/features/mpa/mpa.ts (1)
58-61
: 逻辑正确,符合预期。
const isLT18 = (() => { | ||
const reactDOMVersion = require(join(reactDOMPath, 'package.json')).version; | ||
const majorVersion = parseInt(reactDOMVersion.split('.')[0], 10); | ||
return majorVersion < 18; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改进 React 版本比较逻辑。
当前的版本比较逻辑通过解析 react-dom
的版本号并提取主版本号来进行比较,这样可以避免字符串比较带来的问题。然而,建议在解析版本号时增加错误处理,以防止版本号格式不正确的情况。
+ const reactDOMVersion = require(join(reactDOMPath, 'package.json')).version;
+ const majorVersion = parseInt(reactDOMVersion.split('.')[0], 10);
+ if (isNaN(majorVersion)) {
+ throw new Error(`Invalid ReactDOM version: ${reactDOMVersion}`);
+ }
+ return majorVersion < 18;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const isLT18 = (() => { | |
const reactDOMVersion = require(join(reactDOMPath, 'package.json')).version; | |
const majorVersion = parseInt(reactDOMVersion.split('.')[0], 10); | |
return majorVersion < 18; | |
})(); | |
const isLT18 = (() => { | |
const reactDOMVersion = require(join(reactDOMPath, 'package.json')).version; | |
const majorVersion = parseInt(reactDOMVersion.split('.')[0], 10); | |
if (isNaN(majorVersion)) { | |
throw new Error(`Invalid ReactDOM version: ${reactDOMVersion}`); | |
} | |
return majorVersion < 18; | |
})(); |
@@ -49,16 +49,16 @@ export default (api: IApi) => { | |||
); | |||
} | |||
|
|||
const isReact18 = api.appData.react.version.startsWith('18.'); | |||
const isGTEReact18 = api.appData.react.version.split('.')[0] >= 18; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改进 React 版本比较逻辑。
当前的版本比较逻辑通过解析 react
的版本号并提取主版本号来进行比较,这样可以避免字符串比较带来的问题。然而,建议在解析版本号时增加错误处理,以防止版本号格式不正确的情况。
- const isGTEReact18 = api.appData.react.version.split('.')[0] >= 18;
+ const reactVersion = api.appData.react.version;
+ const majorVersion = parseInt(reactVersion.split('.')[0], 10);
+ if (isNaN(majorVersion)) {
+ throw new Error(`Invalid React version: ${reactVersion}`);
+ }
+ const isGTEReact18 = majorVersion >= 18;
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const isGTEReact18 = api.appData.react.version.split('.')[0] >= 18; | |
const reactVersion = api.appData.react.version; | |
const majorVersion = parseInt(reactVersion.split('.')[0], 10); | |
if (isNaN(majorVersion)) { | |
throw new Error(`Invalid React version: ${reactVersion}`); | |
} | |
const isGTEReact18 = majorVersion >= 18; |
v19 废弃了 findDOMNode ,之前很多库都用到了这个 api 所以会很容易出警告,等社区的各种包跟进更新吧,根据报错堆栈你可以知道是哪个库用的,如果他们更新了,你更新下依赖版本即可。 |
.
Summary by CodeRabbit