-
Notifications
You must be signed in to change notification settings - Fork 199
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 18 (兼容 React 16/17) #2373
Conversation
兼容 React 16 和 React 18, tooltip 异步挂载 BREAKING CHANGE: 支持 React 18
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
你好, @lijinke666 CI 执行失败, 请点击 [Details] 按钮查看, 并根据日志修复。 Hello, @lijinke666 CI run failed, please click the [Details] button for detailed log information and fix it. |
@@ -1,3 +1,4 @@ | |||
npm_config_legacy_peer_deps=true | |||
side-effects-cache=false | |||
prefer-workspace-packages=true | |||
auto-install-peers=false |
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.
CI 升级到 pnpm 8 后安装依赖报错的解决方案
}, 50); | ||
} else { | ||
this.tooltip.show?.({ | ||
return new Promise((resolve) => { |
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 集成 BaseTooltip 后, 由于挂载方式变成了 createRoot().render()
异步的方式, 所以在 core 要做对应的适配, 不然在 s2.showTooltip()
后拿不到最新的 dom
Size Change: +1.22 kB (0%) Total Size: 321 kB
ℹ️ View Unchanged
|
@@ -23,32 +23,30 @@ export const BaseSheet: React.FC<SheetComponentsProps> = React.memo((props) => { | |||
}, [props.themeCfg?.name]); | |||
|
|||
return ( | |||
<React.StrictMode> |
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.
TODO: React 18 StrictMode 在开发模式下会强制 render 两次, 需要兼容
} | ||
|
||
ReactDOM.render( | ||
this.isMobileType() ? ( | ||
this.root ??= createRoot(this.container!); |
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.
18 render 后取消了回调, 通过 useEffect
做后续操作, 通过 ref 传递的方式, 以便于 createRoot().render()
后能知道 tooltip
的 container
已挂载
@@ -22,7 +22,7 @@ import type { TooltipRenderProps } from './interface'; | |||
import './index.less'; | |||
|
|||
export const TooltipComponent = (props: TooltipRenderProps) => { | |||
const { data, options, content, cell } = props; | |||
const { data, options, content, cell, onMounted } = props; |
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.
解决 createRoot().render() 渲染后触发回调的问题
jsc: { | ||
transform: { | ||
// https://swc.rs/docs/configuration/compilation#jsctransformusedefineforclassfields | ||
useDefineForClassFields: false, |
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2373 +/- ##
==========================================
+ Coverage 75.77% 77.77% +2.00%
==========================================
Files 257 268 +11
Lines 11994 12007 +13
Branches 2464 2432 -32
==========================================
+ Hits 9088 9338 +250
+ Misses 1398 1168 -230
+ Partials 1508 1501 -7
☔ View full report in Codecov by Sentry. |
if (this.container) { | ||
ReactDOM.unmountComponentAtNode(this.container); | ||
private unmount() { | ||
if (this.isLegacyReactVersion && this.container!) { |
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.
🎉 This PR is included in version @antv/s2-v2.0.0-next.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version @antv/s2-react-v2.0.0-next.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version @antv/s2-vue-v2.0.0-next.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
👀 PR includes
✨ Feature
📝 Description
BREAKING CHANGE: 支持 React 18, 参考 https://zh-hans.react.dev/blog/2022/03/08/react-18-upgrade-guide
🖼️ Screenshot
🔗 Related issue link
ref #2270
🔍 Self-Check before the merge