From c5d9fd3ebf43d537f8ad32525791f88361bec021 Mon Sep 17 00:00:00 2001 From: MrWangJustToDo <2711470541@qq.com> Date: Mon, 6 May 2024 18:43:13 +0800 Subject: [PATCH] update refresh package --- .../myreact-refresh/src/RefreshBabelPlugin.ts | 18 +++++++++++++++ ui/next-example/tsconfig.json | 22 ++++++++++++++++--- ui/ssr-example/build/scripts/config.ts | 9 ++++++-- .../src/client/container/Section/Main.tsx | 4 ++-- ui/ssr-example/src/shared/template/Head.tsx | 4 ++-- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/packages/myreact-refresh/src/RefreshBabelPlugin.ts b/packages/myreact-refresh/src/RefreshBabelPlugin.ts index 3a3703b3..4b911dcb 100644 --- a/packages/myreact-refresh/src/RefreshBabelPlugin.ts +++ b/packages/myreact-refresh/src/RefreshBabelPlugin.ts @@ -212,6 +212,24 @@ export default function (babel, opts: Record = {}) { case "React.useImperativeHandle": case "useDebugValue": case "React.useDebugValue": + case "useId": + case "React.useId": + case "useDeferredValue": + case "React.useDeferredValue": + case "useTransition": + case "React.useTransition": + case "useInsertionEffect": + case "React.useInsertionEffect": + case "useSyncExternalStore": + case "React.useSyncExternalStore": + case "useFormStatus": + case "React.useFormStatus": + case "useFormState": + case "React.useFormState": + case "useActionState": + case "React.useActionState": + case "useOptimistic": + case "React.useOptimistic": return true; default: return false; diff --git a/ui/next-example/tsconfig.json b/ui/next-example/tsconfig.json index c0d0be59..0aed5a87 100644 --- a/ui/next-example/tsconfig.json +++ b/ui/next-example/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -15,7 +19,19 @@ "jsx": "preserve", "baseUrl": ".", "incremental": true, + "plugins": [ + { + "name": "next" + } + ] }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts" + ], + "exclude": [ + "node_modules" + ] } diff --git a/ui/ssr-example/build/scripts/config.ts b/ui/ssr-example/build/scripts/config.ts index 12989d16..ee2b1f78 100644 --- a/ui/ssr-example/build/scripts/config.ts +++ b/ui/ssr-example/build/scripts/config.ts @@ -2,9 +2,14 @@ import LoadablePlugin from "@loadable/webpack-plugin"; import RefreshWebpackPlugin from "@my-react/react-refresh-tools/RefreshWebpackPlugin"; import ReactRefreshPlugin from "@pmmmwh/react-refresh-webpack-plugin"; import { MANIFEST, definedWebpackConfig, WebpackNodeExternals } from "@site/webpack"; +import dayjs from "dayjs"; import { resolve } from "path"; import { DefinePlugin, HotModuleReplacementPlugin } from "webpack"; +require("dayjs/locale/zh-cn"); + +dayjs.locale("zh-cn"); + export const getConfig = () => { const multiConfig = definedWebpackConfig({ serverEntry: process.env.SERVER_ENTRY!, @@ -26,7 +31,7 @@ export const getConfig = () => { __BASENAME__: JSON.stringify(process.env.BASENAME || ""), __BUNDLE_SCOPE__: JSON.stringify(BUNDLE_SCOPE), __OUTPUT_SCOPE__: JSON.stringify(OUTPUT_SCOPE), - __BUILD_TIME__: JSON.stringify(new Date().toLocaleString()), + __BUILD_TIME__: JSON.stringify(dayjs().toString()), }), isDEV && (isReact ? new ReactRefreshPlugin() : new RefreshWebpackPlugin()), isDEV && isMIDDLEWARE && new HotModuleReplacementPlugin(), @@ -71,7 +76,7 @@ export const getConfig = () => { __BASENAME__: JSON.stringify(process.env.BASENAME || ""), __BUNDLE_SCOPE__: JSON.stringify(BUNDLE_SCOPE), __OUTPUT_SCOPE__: JSON.stringify(OUTPUT_SCOPE), - __BUILD_TIME__: JSON.stringify(new Date().toLocaleString()), + __BUILD_TIME__: JSON.stringify(dayjs().toString()), }), isDEV && !isMIDDLEWARE && new HotModuleReplacementPlugin(), ].filter(Boolean); diff --git a/ui/ssr-example/src/client/container/Section/Main.tsx b/ui/ssr-example/src/client/container/Section/Main.tsx index d09b31d4..fdc2203a 100644 --- a/ui/ssr-example/src/client/container/Section/Main.tsx +++ b/ui/ssr-example/src/client/container/Section/Main.tsx @@ -14,7 +14,7 @@ const { enableMockReact } = __my_react_shared__; const tsxMd = ` \`\`\`tsx import { useState, useCallback } from '@my-react/react'; -import { render } from '@my-react/react-dom'; +import { createRoot } from '@my-react/react-dom'; /** * hello world @@ -38,7 +38,7 @@ const App = () => { } -render(, document.querySelector('#root')); +createRoot(document.querySelector('#root')).render(); \`\`\` `; diff --git a/ui/ssr-example/src/shared/template/Head.tsx b/ui/ssr-example/src/shared/template/Head.tsx index e5e91c40..8068a7e4 100644 --- a/ui/ssr-example/src/shared/template/Head.tsx +++ b/ui/ssr-example/src/shared/template/Head.tsx @@ -13,9 +13,9 @@ export const Head = ({ env = "{}", link = [], preLoad = [], preloadedState = "{} - +