Skip to content
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

fix: use reactRender from react-dom/client in React 19 #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deathemperor
Copy link

@deathemperor deathemperor commented Dec 21, 2024

fix #550

Summary by CodeRabbit

  • 新特性

    • 更新了渲染和卸载逻辑,以支持 React 18 的新 API。
    • 引入了现代渲染和卸载方法,提供更好的性能和兼容性。
  • 文档

    • 更新了导出或公共实体的类型别名和函数签名。

Copy link

vercel bot commented Dec 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
util ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 21, 2024 6:21pm

Copy link

coderabbitai bot commented Dec 21, 2024

演练

此次更改主要针对 React 渲染和卸载机制进行了更新,以适配 React 18 的新 API。修改包括更新导入语句、引入新的渲染和卸载逻辑,并确保与旧版本 React 的兼容性。主要变更涉及使用 createRoot 方法处理渲染和卸载,同时为不同版本的 React 提供了向后兼容的解决方案。

变更

文件 变更摘要
src/React/render.ts - 更新 ReactDOM 导入为 react-dom/client
- 引入 CreateRoot 类型别名
- 添加 modernRendermodernUnmount 函数
- 更新 renderunmount 函数以支持 React 18

序列图

sequenceDiagram
    participant App as 应用程序
    participant Render as 渲染模块
    participant ReactDOM as ReactDOM
    
    alt React 版本 >= 18
        App->>Render: 调用渲染
        Render->>ReactDOM: 使用 createRoot
        ReactDOM-->>Render: 创建根容器
    else React 版本 < 18
        App->>Render: 调用渲染
        Render->>ReactDOM: 使用传统渲染方法
        ReactDOM-->>Render: 渲染完成
    end
Loading

目标评估

目标 已解决 说明
确保 render 函数适配 React 19-RC ( #550 )
更新导入语句以反映 React 18 API ( #550 )

可能相关的 PR

诗歌

🐰 兔子渲染的魔法歌 🎨
React 18 来敲门,新 API 闪亮登场
创建根容器,渲染更轻松
旧方法不慌,兼容性依然强
代码如诗,兔子笑得开怀!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 283a6de and 8b32934.

📒 Files selected for processing (1)
  • src/React/render.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/React/render.ts

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/React/render.ts (2)

Line range hint 14-18: 在获取主版本时的异常处理有助于兼容旧版本或缺失版本信息的情况。
使用 try/catch 捕获并忽略错误是一个简洁方法。但需要确保后续逻辑不会在版本号无法获取时发生意料之外的问题。


Line range hint 30-37: toggleWarning 函数对内部使用的警告标志做了按需切换,逻辑清晰。
此处可考虑在生产环境下跳过该逻辑,以减少不必要的副作用。同时不要在意外场景下长时间保持该标志为 true。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea33203 and 283a6de.

📒 Files selected for processing (1)
  • src/React/render.ts (1 hunks)
🔇 Additional comments (2)
src/React/render.ts (2)

2-2: 切换至 React 18 的 'react-dom/client' 导入看起来不错。
使用新版 API 有助于支持 createRoot 等特性,同时与 React 18 的渲染流程保持一致。但需确保项目的 react 版本在 18 及以上。


Line range hint 60-68: modernUnmount 中异步延迟卸载能有效避免 React 18 的告警,但要注意被延迟卸载的组件行为。
目前做了 Promise.resolve().then(...) 的延迟调用,不会阻塞线程,能够在 React 18 中避免同步警告。若后续组件在卸载前还有其他异步操控需求,需额外保证逻辑有序执行。

@deathemperor deathemperor changed the title fix https://github.com/react-component/util/issues/550 fix: use reactRender from react-dom/client in React 19 Dec 21, 2024
@deathemperor
Copy link
Author

closing as it's fixed in v5.44.2...v5.44.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"render" function throws "reactRender is not a function" with react 19-rc
1 participant