-
Notifications
You must be signed in to change notification settings - Fork 196
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: 支持同时在 React 16/17/18 下运行 #2802
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: +67 B (+0.02%) Total Size: 326 kB
ℹ️ View Unchanged
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #2802 +/- ##
==========================================
+ Coverage 75.77% 80.23% +4.46%
==========================================
Files 257 181 -76
Lines 11994 10384 -1610
Branches 2464 2344 -120
==========================================
- Hits 9088 8332 -756
+ Misses 1398 607 -791
+ Partials 1508 1445 -63 ☔ View full report in Codecov by Sentry. |
let createRoot: CreateRoot; | ||
|
||
try { | ||
const mainVersion = Number((version || '').split('.')[0]); |
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.
参考 antd 的 react-component/util 处理, 做一个克隆, 动态生成 createRoot
*/ | ||
import { version } from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import type { Root } from 'react-dom/client'; |
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.
import type
不受影响
jest.mock('react', () => { | ||
return { | ||
...jest.requireActual('react'), | ||
version: '16.9.0', |
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.
判断不同版本的 render
和 unmount
执行分支
🎉 This PR is included in version @antv/s2-react-v2.0.0-next.24 🎉 The release is available on: Your semantic-release bot 📦🚀 |
👀 PR includes
✨ Feature
📝 Description
原本 Tooltip 做了 React 16/18 的兼容, 但在实际运行时
react-dom/client
的方式打包工具会报错本质上
react-dom/client
是react-dom
的一个 sub modulehttps://github.com/facebook/react/blob/main/packages/react-dom/package.json#L51-L59
所以参考 antd 的处理方式, 使用
import *
的方式全部引入, 然后做一个克隆, 跟进版本动态判断是否使用createRoot
https://github.com/react-component/util/blob/677d3ac177d147572b65af63e67a7796a5104f4c/src/React/render.ts#L6-L13
其他:
React 19 已发布 RC 版本, 社区负面反馈较多, 后续兼容视React 19 稳定情况而定。
🖼️ Screenshot
🔗 Related issue link
🔍 Self-Check before the merge