From beee5db34c4b80b88b8231921b4592995d347bc9 Mon Sep 17 00:00:00 2001 From: MrWangJustToDo <2711470541@qq.com> Date: Thu, 14 Nov 2024 14:23:57 +0800 Subject: [PATCH] support react compiler --- packages/myreact/src/index.ts | 20 ++++- pnpm-lock.yaml | 125 +++++++++++++++++++------------- ui/next-example/next.config.mjs | 15 +++- ui/next-example/package.json | 6 +- 4 files changed, 108 insertions(+), 58 deletions(-) diff --git a/packages/myreact/src/index.ts b/packages/myreact/src/index.ts index 21c64cb2..21e6b5d0 100644 --- a/packages/myreact/src/index.ts +++ b/packages/myreact/src/index.ts @@ -73,7 +73,25 @@ const version = enableMockReact.current ? "18.2.0" : __VERSION__; const __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = { ReactCurrentActQueue: {}, ReactCurrentBatchConfig: {}, - ReactCurrentDispatcher: { current: {} }, + ReactCurrentDispatcher: { + current: { + useCallback, + useContext, + useDebugValue, + useDeferredValue, + useEffect, + useId, + useImperativeHandle, + useInsertionEffect, + useLayoutEffect, + useMemo, + useReducer, + useRef, + useState, + useSyncExternalStore, + useTransition, + }, + }, ReactCurrentOwner: { current: null }, ReactDebugCurrentFrame: {}, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7df7d80..72278b9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -710,8 +710,8 @@ importers: specifier: ^8.57.0 version: 8.57.0 next: - specifier: ^15.0.2 - version: 15.0.2(@babel/core@7.25.2)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.80.5) + specifier: ^15.0.3 + version: 15.0.3(@babel/core@7.25.2)(babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.80.5) postcss: specifier: ^8.4.47 version: 8.4.47 @@ -728,12 +728,18 @@ importers: specifier: ^5.3.3 version: 5.3.3 devDependencies: + babel-plugin-react-compiler: + specifier: 19.0.0-beta-a7bf2bd-20241110 + version: 19.0.0-beta-a7bf2bd-20241110 esm-module-alias: specifier: ^2.2.0 version: 2.2.0 module-alias: specifier: ^2.2.3 version: 2.2.3 + react-compiler-runtime: + specifier: 19.0.0-beta-a7bf2bd-20241110 + version: 19.0.0-beta-a7bf2bd-20241110(react@18.2.0) ui/remix-example: dependencies: @@ -770,7 +776,7 @@ importers: version: link:../../packages/myreact-vite '@remix-run/dev': specifier: ^2.13.1 - version: 2.13.1(@remix-run/react@2.13.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(typescript@5.3.3))(@remix-run/serve@2.13.1(typescript@5.3.3))(@types/node@22.8.4)(babel-plugin-macros@3.1.0)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)(ts-node@10.9.2(@swc/core@1.7.40(@swc/helpers@0.5.13))(@types/node@22.8.4)(typescript@5.3.3))(typescript@5.3.3)(vite@5.4.10(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)) + version: 2.13.1(@remix-run/react@2.13.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(typescript@5.3.3))(@remix-run/serve@2.13.1(typescript@5.3.3))(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)(ts-node@10.9.2(@swc/core@1.7.40(@swc/helpers@0.5.13))(@types/node@22.8.4)(typescript@5.3.3))(typescript@5.3.3)(vite@5.4.10(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)) '@types/react': specifier: ^18.2.58 version: 18.3.12 @@ -3578,53 +3584,53 @@ packages: '@mdx-js/mdx@2.3.0': resolution: {integrity: sha512-jLuwRlz8DQfQNiUCJR50Y09CGPq3fLtmtUQfVrj79E0JWu3dvsVcxVIcfhR5h0iXu+/z++zDrYeiJqifRynJkA==} - '@next/env@15.0.2': - resolution: {integrity: sha512-c0Zr0ModK5OX7D4ZV8Jt/wqoXtitLNPwUfG9zElCZztdaZyNVnN40rDXVZ/+FGuR4CcNV5AEfM6N8f+Ener7Dg==} + '@next/env@15.0.3': + resolution: {integrity: sha512-t9Xy32pjNOvVn2AS+Utt6VmyrshbpfUMhIjFO60gI58deSo/KgLOp31XZ4O+kY/Is8WAGYwA5gR7kOb1eORDBA==} - '@next/swc-darwin-arm64@15.0.2': - resolution: {integrity: sha512-GK+8w88z+AFlmt+ondytZo2xpwlfAR8U6CRwXancHImh6EdGfHMIrTSCcx5sOSBei00GyLVL0ioo1JLKTfprgg==} + '@next/swc-darwin-arm64@15.0.3': + resolution: {integrity: sha512-s3Q/NOorCsLYdCKvQlWU+a+GeAd3C8Rb3L1YnetsgwXzhc3UTWrtQpB/3eCjFOdGUj5QmXfRak12uocd1ZiiQw==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] - '@next/swc-darwin-x64@15.0.2': - resolution: {integrity: sha512-KUpBVxIbjzFiUZhiLIpJiBoelqzQtVZbdNNsehhUn36e2YzKHphnK8eTUW1s/4aPy5kH/UTid8IuVbaOpedhpw==} + '@next/swc-darwin-x64@15.0.3': + resolution: {integrity: sha512-Zxl/TwyXVZPCFSf0u2BNj5sE0F2uR6iSKxWpq4Wlk/Sv9Ob6YCKByQTkV2y6BCic+fkabp9190hyrDdPA/dNrw==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] - '@next/swc-linux-arm64-gnu@15.0.2': - resolution: {integrity: sha512-9J7TPEcHNAZvwxXRzOtiUvwtTD+fmuY0l7RErf8Yyc7kMpE47MIQakl+3jecmkhOoIyi/Rp+ddq7j4wG6JDskQ==} + '@next/swc-linux-arm64-gnu@15.0.3': + resolution: {integrity: sha512-T5+gg2EwpsY3OoaLxUIofmMb7ohAUlcNZW0fPQ6YAutaWJaxt1Z1h+8zdl4FRIOr5ABAAhXtBcpkZNwUcKI2fw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@next/swc-linux-arm64-musl@15.0.2': - resolution: {integrity: sha512-BjH4ZSzJIoTTZRh6rG+a/Ry4SW0HlizcPorqNBixBWc3wtQtj4Sn9FnRZe22QqrPnzoaW0ctvSz4FaH4eGKMww==} + '@next/swc-linux-arm64-musl@15.0.3': + resolution: {integrity: sha512-WkAk6R60mwDjH4lG/JBpb2xHl2/0Vj0ZRu1TIzWuOYfQ9tt9NFsIinI1Epma77JVgy81F32X/AeD+B2cBu/YQA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@next/swc-linux-x64-gnu@15.0.2': - resolution: {integrity: sha512-i3U2TcHgo26sIhcwX/Rshz6avM6nizrZPvrDVDY1bXcLH1ndjbO8zuC7RoHp0NSK7wjJMPYzm7NYL1ksSKFreA==} + '@next/swc-linux-x64-gnu@15.0.3': + resolution: {integrity: sha512-gWL/Cta1aPVqIGgDb6nxkqy06DkwJ9gAnKORdHWX1QBbSZZB+biFYPFti8aKIQL7otCE1pjyPaXpFzGeG2OS2w==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@next/swc-linux-x64-musl@15.0.2': - resolution: {integrity: sha512-AMfZfSVOIR8fa+TXlAooByEF4OB00wqnms1sJ1v+iu8ivwvtPvnkwdzzFMpsK5jA2S9oNeeQ04egIWVb4QWmtQ==} + '@next/swc-linux-x64-musl@15.0.3': + resolution: {integrity: sha512-QQEMwFd8r7C0GxQS62Zcdy6GKx999I/rTO2ubdXEe+MlZk9ZiinsrjwoiBL5/57tfyjikgh6GOU2WRQVUej3UA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@next/swc-win32-arm64-msvc@15.0.2': - resolution: {integrity: sha512-JkXysDT0/hEY47O+Hvs8PbZAeiCQVxKfGtr4GUpNAhlG2E0Mkjibuo8ryGD29Qb5a3IOnKYNoZlh/MyKd2Nbww==} + '@next/swc-win32-arm64-msvc@15.0.3': + resolution: {integrity: sha512-9TEp47AAd/ms9fPNgtgnT7F3M1Hf7koIYYWCMQ9neOwjbVWJsHZxrFbI3iEDJ8rf1TDGpmHbKxXf2IFpAvheIQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] - '@next/swc-win32-x64-msvc@15.0.2': - resolution: {integrity: sha512-foaUL0NqJY/dX0Pi/UcZm5zsmSk5MtP/gxx3xOPyREkMFN+CTjctPfu3QaqrQHinaKdPnMWPJDKt4VjDfTBe/Q==} + '@next/swc-win32-x64-msvc@15.0.3': + resolution: {integrity: sha512-VNAz+HN4OGgvZs6MOoVfnn41kBzT+M+tB+OK4cww6DNyWS6wKaDpaAm/qLeOUbnMh0oVx1+mg0uoYARF69dJyA==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -5547,6 +5553,9 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110: + resolution: {integrity: sha512-WdxXtLxsV4gh/GlEK4fuFDGkcED0Wb9UJEBB6Uc1SFqRFEmJNFKboW+Z4NUS5gYrPImqrjh4IwHAmgS6ZBg4Cg==} + babel-plugin-syntax-trailing-function-commas@7.0.0-beta.0: resolution: {integrity: sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ==} @@ -8427,16 +8436,16 @@ packages: next-tick@1.1.0: resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} - next@15.0.2: - resolution: {integrity: sha512-rxIWHcAu4gGSDmwsELXacqAPUk+j8dV/A9cDF5fsiCMpkBDYkO2AEaL1dfD+nNmDiU6QMCFN8Q30VEKapT9UHQ==} - engines: {node: '>=18.18.0'} + next@15.0.3: + resolution: {integrity: sha512-ontCbCRKJUIoivAdGB34yCaOcPgYXr9AAkV/IwqFfWWTXEPUgLYkSkqBhIk9KK7gGmgjc64B+RdoeIDM13Irnw==} + engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0} hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 '@playwright/test': ^1.41.2 babel-plugin-react-compiler: '*' - react: ^18.2.0 || 19.0.0-rc-02c0e824-20241028 - react-dom: ^18.2.0 || 19.0.0-rc-02c0e824-20241028 + react: ^18.2.0 || 19.0.0-rc-66855b96-20241106 + react-dom: ^18.2.0 || 19.0.0-rc-66855b96-20241106 sass: ^1.3.0 peerDependenciesMeta: '@opentelemetry/api': @@ -9286,6 +9295,11 @@ packages: peerDependencies: react: ^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 + react-compiler-runtime@19.0.0-beta-a7bf2bd-20241110: + resolution: {integrity: sha512-cSkrfz2eGcC9UZ/83mLf3aqKKDVjFkWJeA/kiYLwKTNp7B0Lq5M1FQ3vTfgSC027fK5ZutXU/JsCS5KxTwk8Mg==} + peerDependencies: + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + react-devtools-inline@4.4.0: resolution: {integrity: sha512-ES0GolSrKO8wsKbsEkVeiR/ZAaHQTY4zDh1UW8DImVmm8oaGLl3ijJDvSGe+qDRKPZdPRnDtWWnSvvrgxXdThQ==} @@ -14481,30 +14495,30 @@ snapshots: transitivePeerDependencies: - supports-color - '@next/env@15.0.2': {} + '@next/env@15.0.3': {} - '@next/swc-darwin-arm64@15.0.2': + '@next/swc-darwin-arm64@15.0.3': optional: true - '@next/swc-darwin-x64@15.0.2': + '@next/swc-darwin-x64@15.0.3': optional: true - '@next/swc-linux-arm64-gnu@15.0.2': + '@next/swc-linux-arm64-gnu@15.0.3': optional: true - '@next/swc-linux-arm64-musl@15.0.2': + '@next/swc-linux-arm64-musl@15.0.3': optional: true - '@next/swc-linux-x64-gnu@15.0.2': + '@next/swc-linux-x64-gnu@15.0.3': optional: true - '@next/swc-linux-x64-musl@15.0.2': + '@next/swc-linux-x64-musl@15.0.3': optional: true - '@next/swc-win32-arm64-msvc@15.0.2': + '@next/swc-win32-arm64-msvc@15.0.3': optional: true - '@next/swc-win32-x64-msvc@15.0.2': + '@next/swc-win32-x64-msvc@15.0.3': optional: true '@nodelib/fs.scandir@2.1.5': @@ -15315,7 +15329,7 @@ snapshots: '@redux-saga/types@1.2.1': {} - '@remix-run/dev@2.13.1(@remix-run/react@2.13.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(typescript@5.3.3))(@remix-run/serve@2.13.1(typescript@5.3.3))(@types/node@22.8.4)(babel-plugin-macros@3.1.0)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)(ts-node@10.9.2(@swc/core@1.7.40(@swc/helpers@0.5.13))(@types/node@22.8.4)(typescript@5.3.3))(typescript@5.3.3)(vite@5.4.10(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1))': + '@remix-run/dev@2.13.1(@remix-run/react@2.13.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(typescript@5.3.3))(@remix-run/serve@2.13.1(typescript@5.3.3))(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)(ts-node@10.9.2(@swc/core@1.7.40(@swc/helpers@0.5.13))(@types/node@22.8.4)(typescript@5.3.3))(typescript@5.3.3)(vite@5.4.10(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1))': dependencies: '@babel/core': 7.25.2 '@babel/generator': 7.25.5 @@ -15332,7 +15346,7 @@ snapshots: '@remix-run/router': 1.20.0 '@remix-run/server-runtime': 2.13.1(typescript@5.3.3) '@types/mdx': 2.0.13 - '@vanilla-extract/integration': 6.5.0(@types/node@22.8.4)(babel-plugin-macros@3.1.0)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1) + '@vanilla-extract/integration': 6.5.0(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1) arg: 5.0.2 cacache: 17.1.4 chalk: 4.1.2 @@ -16165,7 +16179,7 @@ snapshots: transitivePeerDependencies: - babel-plugin-macros - '@vanilla-extract/integration@6.5.0(@types/node@22.8.4)(babel-plugin-macros@3.1.0)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)': + '@vanilla-extract/integration@6.5.0(@types/node@22.8.4)(sass@1.80.5)(sugarss@4.0.1(postcss@8.4.47))(terser@5.28.1)': dependencies: '@babel/core': 7.25.2 '@babel/plugin-syntax-typescript': 7.23.3(@babel/core@7.25.2) @@ -16683,6 +16697,10 @@ snapshots: transitivePeerDependencies: - supports-color + babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110: + dependencies: + '@babel/types': 7.25.4 + babel-plugin-syntax-trailing-function-commas@7.0.0-beta.0: {} babel-preset-fbjs@3.4.0(@babel/core@7.25.2): @@ -20083,26 +20101,27 @@ snapshots: next-tick@1.1.0: {} - next@15.0.2(@babel/core@7.25.2)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.80.5): + next@15.0.3(@babel/core@7.25.2)(babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.80.5): dependencies: - '@next/env': 15.0.2 + '@next/env': 15.0.3 '@swc/counter': 0.1.3 '@swc/helpers': 0.5.13 busboy: 1.6.0 - caniuse-lite: 1.0.30001651 + caniuse-lite: 1.0.30001675 postcss: 8.4.31 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) styled-jsx: 5.1.6(@babel/core@7.25.2)(react@18.2.0) optionalDependencies: - '@next/swc-darwin-arm64': 15.0.2 - '@next/swc-darwin-x64': 15.0.2 - '@next/swc-linux-arm64-gnu': 15.0.2 - '@next/swc-linux-arm64-musl': 15.0.2 - '@next/swc-linux-x64-gnu': 15.0.2 - '@next/swc-linux-x64-musl': 15.0.2 - '@next/swc-win32-arm64-msvc': 15.0.2 - '@next/swc-win32-x64-msvc': 15.0.2 + '@next/swc-darwin-arm64': 15.0.3 + '@next/swc-darwin-x64': 15.0.3 + '@next/swc-linux-arm64-gnu': 15.0.3 + '@next/swc-linux-arm64-musl': 15.0.3 + '@next/swc-linux-x64-gnu': 15.0.3 + '@next/swc-linux-x64-musl': 15.0.3 + '@next/swc-win32-arm64-msvc': 15.0.3 + '@next/swc-win32-x64-msvc': 15.0.3 + babel-plugin-react-compiler: 19.0.0-beta-a7bf2bd-20241110 sass: 1.80.5 sharp: 0.33.5 transitivePeerDependencies: @@ -20806,8 +20825,8 @@ snapshots: postcss@8.4.31: dependencies: nanoid: 3.3.7 - picocolors: 1.0.1 - source-map-js: 1.2.0 + picocolors: 1.1.1 + source-map-js: 1.2.1 postcss@8.4.47: dependencies: @@ -20988,6 +21007,10 @@ snapshots: '@babel/runtime': 7.23.6 react: 18.2.0 + react-compiler-runtime@19.0.0-beta-a7bf2bd-20241110(react@18.2.0): + dependencies: + react: 18.2.0 + react-devtools-inline@4.4.0: dependencies: es6-symbol: 3.1.3 diff --git a/ui/next-example/next.config.mjs b/ui/next-example/next.config.mjs index e395d54d..99e04b45 100644 --- a/ui/next-example/next.config.mjs +++ b/ui/next-example/next.config.mjs @@ -1,10 +1,17 @@ import withNext from "@my-react/react-refresh-tools/withNext"; /** @type {import('next').NextConfig} */ -const nextConfig = withNext({ +const config = { reactStrictMode: true, -}); + experimental: { + reactCompiler: { + target: '18', + }, // or React Compiler options + }, +} -export default nextConfig; +const nextConfig = withNext(config); + +// export default config; -// module.exports = nextConfig; +export default nextConfig; diff --git a/ui/next-example/package.json b/ui/next-example/package.json index 2cf807cb..cb60e1c8 100644 --- a/ui/next-example/package.json +++ b/ui/next-example/package.json @@ -19,7 +19,7 @@ "@types/react-dom": "^18.2.19", "autoprefixer": "^10.4.20", "eslint": "^8.57.0", - "next": "^15.0.2", + "next": "^15.0.3", "postcss": "^8.4.47", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -35,7 +35,9 @@ "react-dom": "node_modules/@my-react/react-dom/index.js" }, "devDependencies": { + "babel-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110", "esm-module-alias": "^2.2.0", - "module-alias": "^2.2.3" + "module-alias": "^2.2.3", + "react-compiler-runtime": "19.0.0-beta-a7bf2bd-20241110" } }