antvis / S2

⚡️ A practical visualization library for tabular analysis.
https://s2.antv.antgroup.com
MIT License
1.46k stars 194 forks source link

feat: 支持同时在 React 16/17/18 下运行 #2802

Closed lijinke666 closed 2 months ago

lijinke666 commented 2 months ago

👀 PR includes

✨ Feature

📝 Description

原本 Tooltip 做了 React 16/18 的兼容, 但在实际运行时 react-dom/client 的方式打包工具会报错

image

本质上 react-dom/clientreact-dom 的一个 sub module

https://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

import * as ReactDOM from 'react-dom';
import type { Root } from 'react-dom/client';

const ReactDOMClone = {
  ...ReactDOM,
} as typeof ReactDOM & {
  __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: {
    usingClientEntryPoint?: boolean;
  };
  createRoot?: CreateRoot;
};

其他:

React 19 已发布 RC 版本, 社区负面反馈较多, 后续兼容视React 19 稳定情况而定。

🖼️ Screenshot

Before After

🔗 Related issue link

🔍 Self-Check before the merge

vercel[bot] commented 2 months ago

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

Name Status Preview Comments Updated (UTC)
antvis-s2 ❌ Failed (Inspect) Jul 3, 2024 7:48am
github-actions[bot] commented 2 months ago

Size Change: +67 B (+0.02%)

Total Size: 326 kB

Filename Size Change
./packages/s2-react/dist/index.min.js 69.9 kB +67 B (+0.1%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `./packages/s2-core/dist/index.min.js` | 228 kB | | `./packages/s2-core/dist/style.min.css` | 388 B | | `./packages/s2-react/dist/style.min.css` | 3.88 kB | | `./packages/s2-vue/dist/index.min.js` | 22 kB | | `./packages/s2-vue/dist/style.min.css` | 1.97 kB |

compressed-size-action

codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 75.71429% with 17 lines in your changes missing coverage. Please review.

Project coverage is 80.23%. Comparing base (ecdc9c8) to head (8dfb7d6). Report is 398 commits behind head on next.

Files Patch % Lines
packages/s2-react/src/utils/reactRender.ts 83.33% 5 Missing and 5 partials :warning:
packages/s2-react/src/utils/invokeComponent.tsx 0.00% 6 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

lijinke666 commented 2 months ago

:tada: This PR is included in version @antv/s2-react-v2.0.0-next.24 :tada:

The release is available on:

Your semantic-release bot :package::rocket: