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

feat: 支持 React 18 (兼容 React 16/17) #2373

Merged
merged 12 commits into from
Oct 31, 2023
Merged

feat: 支持 React 18 (兼容 React 16/17) #2373

merged 12 commits into from
Oct 31, 2023

Conversation

lijinke666
Copy link
Member

@lijinke666 lijinke666 commented Oct 16, 2023

👀 PR includes

✨ Feature

  • New feature

📝 Description

BREAKING CHANGE: 支持 React 18, 参考 https://zh-hans.react.dev/blog/2022/03/08/react-18-upgrade-guide

  • Tooltip 异步挂载, 支持 React 18 的方式渲染
  • 兼容 React Strict 渲染两次的问题
  • core 层 tooltip API 改造
  • 单测 createRoot
  • 兼容 React 16
  • TypeScript 5/开发包升级
  • pnpm v8
  • swc/jest 单测问题修复

🖼️ Screenshot

Before After

🔗 Related issue link

ref #2270

🔍 Self-Check before the merge

  • Add or update relevant docs.
  • Add or update relevant demos.
  • Add or update test case.
  • Add or update relevant TypeScript definitions.

兼容 React 16 和 React 18, tooltip 异步挂载

BREAKING CHANGE: 支持 React 18
@vercel
Copy link

vercel bot commented Oct 16, 2023

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

Name Status Preview Comments Updated (UTC)
antvis-s2 ❌ Failed (Inspect) Oct 31, 2023 9:24am

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2023

你好, @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
Copy link
Member Author

@lijinke666 lijinke666 Oct 17, 2023

Choose a reason for hiding this comment

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

pnpm/pnpm#6649 (comment)

CI 升级到 pnpm 8 后安装依赖报错的解决方案

}, 50);
} else {
this.tooltip.show?.({
return new Promise((resolve) => {
Copy link
Member Author

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 17, 2023

Size Change: +1.22 kB (0%)

Total Size: 321 kB

Filename Size Change
./packages/s2-core/dist/index.min.js 227 kB +946 B (0%)
./packages/s2-react/dist/index.min.js 67.2 kB +270 B (0%)
./packages/s2-react/dist/style.min.css 3.92 kB +4 B (0%)
./packages/s2-vue/dist/style.min.css 1.91 kB -4 B (0%)
ℹ️ View Unchanged
Filename Size
./packages/s2-core/dist/style.min.css 401 B
./packages/s2-vue/dist/index.min.js 20.2 kB

compressed-size-action

@@ -23,32 +23,30 @@ export const BaseSheet: React.FC<SheetComponentsProps> = React.memo((props) => {
}, [props.themeCfg?.name]);

return (
<React.StrictMode>
Copy link
Member Author

@lijinke666 lijinke666 Oct 17, 2023

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!);
Copy link
Member Author

@lijinke666 lijinke666 Oct 17, 2023

Choose a reason for hiding this comment

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

参考 reactwg/react-18#5

18 render 后取消了回调, 通过 useEffect 做后续操作, 通过 ref 传递的方式, 以便于 createRoot().render() 后能知道 tooltipcontainer 已挂载

image

@@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

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

解决 createRoot().render() 渲染后触发回调的问题

reactwg/react-18#5

jsc: {
transform: {
// https://swc.rs/docs/configuration/compilation#jsctransformusedefineforclassfields
useDefineForClassFields: false,
Copy link
Member Author

@lijinke666 lijinke666 Oct 18, 2023

Choose a reason for hiding this comment

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

解决 @swc/jest test 编译问题, 默认会代理所有 class field, 导致部分单测挂了

image

@github-actions github-actions bot removed the 🚨 lint failed 静态检查失败 label Oct 18, 2023
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ecdc9c8) 75.77% compared to head (dc4d327) 77.77%.
Report is 207 commits behind head on next.

❗ Current head dc4d327 differs from pull request most recent head 916fbb0. Consider uploading reports for the commit 916fbb0 to get more accurate results

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     
Files Coverage Δ
packages/s2-core/src/cell/base-cell.ts 83.95% <ø> (-0.26%) ⬇️
packages/s2-core/src/cell/col-cell.ts 89.47% <ø> (+2.70%) ⬆️
packages/s2-core/src/cell/corner-cell.ts 82.00% <ø> (-0.70%) ⬇️
packages/s2-core/src/cell/data-cell.ts 76.62% <ø> (+9.95%) ⬆️
packages/s2-core/src/cell/header-cell.ts 64.13% <ø> (-1.69%) ⬇️
packages/s2-core/src/cell/index.ts 100.00% <ø> (ø)
packages/s2-core/src/cell/merged-cell.ts 91.66% <ø> (+54.16%) ⬆️
packages/s2-core/src/cell/row-cell.ts 71.42% <ø> (+0.62%) ⬆️
packages/s2-core/src/cell/series-number-cell.ts 90.90% <ø> (-2.20%) ⬇️
packages/s2-core/src/cell/table-col-cell.ts 86.27% <ø> (+5.14%) ⬆️
... and 96 more

... and 169 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lijinke666 lijinke666 changed the title [WIP] feat: 支持 React 18 feat: 支持 React 18 Oct 18, 2023
@github-actions github-actions bot added the pr(feature) new feature label Oct 18, 2023
if (this.container) {
ReactDOM.unmountComponentAtNode(this.container);
private unmount() {
if (this.isLegacyReactVersion && this.container!) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@lijinke666 lijinke666 changed the title feat: 支持 React 18 feat: 支持 React 18 (兼容 React 16/17) Oct 31, 2023
@github-actions github-actions bot removed the 🚨 test failed 单元测试挂了 label Oct 31, 2023
@lijinke666 lijinke666 merged commit 25ce9b0 into next Oct 31, 2023
5 of 6 checks passed
@lijinke666 lijinke666 deleted the feat-react-18 branch October 31, 2023 09:51
@lijinke666
Copy link
Member Author

🎉 This PR is included in version @antv/s2-v2.0.0-next.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lijinke666
Copy link
Member Author

🎉 This PR is included in version @antv/s2-react-v2.0.0-next.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lijinke666
Copy link
Member Author

🎉 This PR is included in version @antv/s2-vue-v2.0.0-next.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next 2.0-next 版本的问题 pr(feature) new feature released on @next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants