From c4f516d5fb92b0a30a949f858eb934d7e705285e Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Tue, 22 Oct 2024 05:39:03 +0000 Subject: [PATCH 1/5] refactor --- src/app/layout.tsx | 3 +- src/features/DebugUI/Content.tsx | 35 +++++++++++++++++++++ src/features/DebugUI/index.tsx | 48 ++++++++++------------------- src/layout/GlobalProvider/index.tsx | 16 ++-------- 4 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 src/features/DebugUI/Content.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index cd85ba817e78..7c0b9902000a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,17 +1,16 @@ import { SpeedInsights } from '@vercel/speed-insights/next'; import { ResolvingViewport } from 'next'; -import dynamic from 'next/dynamic'; import { cookies } from 'next/headers'; import { ReactNode } from 'react'; import { isRtlLang } from 'rtl-detect'; import Analytics from '@/components/Analytics'; import { DEFAULT_LANG, LOBE_LOCALE_COOKIE } from '@/const/locale'; +import PWAInstall from '@/features/PWAInstall'; import AuthProvider from '@/layout/AuthProvider'; import GlobalProvider from '@/layout/GlobalProvider'; import { isMobileDevice } from '@/utils/responsive'; -const PWAInstall = dynamic(() => import('@/features/PWAInstall'), { ssr: false }); const inVercel = process.env.VERCEL === '1'; type RootLayoutProps = { diff --git a/src/features/DebugUI/Content.tsx b/src/features/DebugUI/Content.tsx new file mode 100644 index 000000000000..81decfa30efe --- /dev/null +++ b/src/features/DebugUI/Content.tsx @@ -0,0 +1,35 @@ + +import { Icon } from '@lobehub/ui'; +import { App, FloatButton, Spin } from 'antd'; +import { DatabaseIcon, Loader2 } from 'lucide-react'; +import { memo, useState } from 'react'; + +import { debugService } from '@/services/debug'; + +const DebugUI = memo(() => { + const [loading, setLoading] = useState(false); + const { message } = App.useApp(); + return ( + <> + {loading && } + } + onClick={async () => { + setLoading(true); + + const startTime = Date.now(); + + await debugService.insertLargeDataToDB(); + + const duration = Date.now() - startTime; + + setLoading(false); + message.success(`插入成功,耗时:${(duration / 1000).toFixed(1)} s`); + }} + tooltip={'性能压测,插入100w数据'} + /> + + ); +}); + +export default DebugUI; diff --git a/src/features/DebugUI/index.tsx b/src/features/DebugUI/index.tsx index 1ecb90b48f5e..580ccb4d3032 100644 --- a/src/features/DebugUI/index.tsx +++ b/src/features/DebugUI/index.tsx @@ -1,36 +1,20 @@ 'use client'; -import { Icon } from '@lobehub/ui'; -import { App, FloatButton, Spin } from 'antd'; -import { DatabaseIcon, Loader2 } from 'lucide-react'; -import { memo, useState } from 'react'; - -import { debugService } from '@/services/debug'; - -const DebugUI = memo(() => { - const [loading, setLoading] = useState(false); - const { message } = App.useApp(); - return ( - <> - {loading && } - } - onClick={async () => { - setLoading(true); - - const startTime = Date.now(); - - await debugService.insertLargeDataToDB(); - - const duration = Date.now() - startTime; - - setLoading(false); - message.success(`插入成功,耗时:${(duration / 1000).toFixed(1)} s`); - }} - tooltip={'性能压测,插入100w数据'} - /> - - ); -}); +import dynamic from 'next/dynamic'; +import { FC } from 'react'; + +import { getDebugConfig } from '@/config/debug'; + +let DebugUI: FC = () => null; + +// we need use Constant Folding to remove code below in production +// refs: https://webpack.js.org/plugins/internal-plugins/#constplugin +if (process.env.NODE_ENV === 'development') { + // eslint-disable-next-line unicorn/no-lonely-if + if (getDebugConfig().DEBUG_MODE) { + // @ts-ignore + DebugUI = dynamic(() => import('./Content'), { ssr: false }); + } +} export default DebugUI; diff --git a/src/layout/GlobalProvider/index.tsx b/src/layout/GlobalProvider/index.tsx index 0dd1535b1a03..9a41aacdd61d 100644 --- a/src/layout/GlobalProvider/index.tsx +++ b/src/layout/GlobalProvider/index.tsx @@ -1,10 +1,8 @@ -import dynamic from 'next/dynamic'; import { cookies, headers } from 'next/headers'; -import { FC, PropsWithChildren } from 'react'; +import { PropsWithChildren } from 'react'; import { resolveAcceptLanguage } from 'resolve-accept-language'; import { appEnv } from '@/config/app'; -import { getDebugConfig } from '@/config/debug'; import { getServerFeatureFlagsValue } from '@/config/featureFlags'; import { LOBE_LOCALE_COOKIE } from '@/const/locale'; import { @@ -12,6 +10,7 @@ import { LOBE_THEME_NEUTRAL_COLOR, LOBE_THEME_PRIMARY_COLOR, } from '@/const/theme'; +import DebugUI from '@/features/DebugUI'; import { locales } from '@/locales/resources'; import { getServerGlobalConfig } from '@/server/globalConfig'; import { ServerConfigStoreProvider } from '@/store/serverConfig'; @@ -24,17 +23,6 @@ import QueryProvider from './Query'; import StoreInitialization from './StoreInitialization'; import StyleRegistry from './StyleRegistry'; -let DebugUI: FC = () => null; - -// we need use Constant Folding to remove code below in production -// refs: https://webpack.js.org/plugins/internal-plugins/#constplugin -if (process.env.NODE_ENV === 'development') { - // eslint-disable-next-line unicorn/no-lonely-if - if (getDebugConfig().DEBUG_MODE) { - DebugUI = dynamic(() => import('@/features/DebugUI'), { ssr: false }) as FC; - } -} - const parserFallbackLang = () => { /** * The arguments are as follows: From 088c3a2ef838b09498ba4f4f21e391c555617af6 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Tue, 22 Oct 2024 14:02:57 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=AF=95=E4=B8=80=E4=B8=8B=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20next=20=E4=BC=9A=E4=B8=8D=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61e50861f3f6..1021e930af92 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ "mammoth": "^1.8.0", "modern-screenshot": "^4.4.39", "nanoid": "^5.0.7", - "next": "14.2.8", + "next": "^14.2.15", "next-auth": "beta", "next-mdx-remote": "^4.4.1", "nextjs-toploader": "^3.7.15", From fb91966e56deb228ceb9967c2bf2a9797f529fb6 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Tue, 22 Oct 2024 06:16:12 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B5=8B=E4=B8=80=E4=B8=8B=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20DebugUI=20=E6=9C=89=E6=B2=A1=E6=9C=89=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/GlobalProvider/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/layout/GlobalProvider/index.tsx b/src/layout/GlobalProvider/index.tsx index 9a41aacdd61d..c567c9d448c1 100644 --- a/src/layout/GlobalProvider/index.tsx +++ b/src/layout/GlobalProvider/index.tsx @@ -10,7 +10,6 @@ import { LOBE_THEME_NEUTRAL_COLOR, LOBE_THEME_PRIMARY_COLOR, } from '@/const/theme'; -import DebugUI from '@/features/DebugUI'; import { locales } from '@/locales/resources'; import { getServerGlobalConfig } from '@/server/globalConfig'; import { ServerConfigStoreProvider } from '@/store/serverConfig'; @@ -81,7 +80,6 @@ const GlobalLayout = async ({ children }: PropsWithChildren) => { {children} - From 887fef4edea556e6b2acb45dd0af16cfc7514ddc Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Tue, 22 Oct 2024 06:24:47 +0000 Subject: [PATCH 4/5] =?UTF-8?q?Revert=20"=E6=B5=8B=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=20DebugUI=20=E6=9C=89=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=A8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fb91966e56deb228ceb9967c2bf2a9797f529fb6. --- src/layout/GlobalProvider/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/layout/GlobalProvider/index.tsx b/src/layout/GlobalProvider/index.tsx index c567c9d448c1..9a41aacdd61d 100644 --- a/src/layout/GlobalProvider/index.tsx +++ b/src/layout/GlobalProvider/index.tsx @@ -10,6 +10,7 @@ import { LOBE_THEME_NEUTRAL_COLOR, LOBE_THEME_PRIMARY_COLOR, } from '@/const/theme'; +import DebugUI from '@/features/DebugUI'; import { locales } from '@/locales/resources'; import { getServerGlobalConfig } from '@/server/globalConfig'; import { ServerConfigStoreProvider } from '@/store/serverConfig'; @@ -80,6 +81,7 @@ const GlobalLayout = async ({ children }: PropsWithChildren) => { {children} + From 42f405c76f2645ed3236a8570da41501380f6259 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Tue, 22 Oct 2024 06:24:54 +0000 Subject: [PATCH 5/5] =?UTF-8?q?Revert=20"=E8=AF=95=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=20next=20=E4=BC=9A=E4=B8=8D=E4=BC=9A?= =?UTF-8?q?=E5=87=BA=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 088c3a2ef838b09498ba4f4f21e391c555617af6. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1021e930af92..61e50861f3f6 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ "mammoth": "^1.8.0", "modern-screenshot": "^4.4.39", "nanoid": "^5.0.7", - "next": "^14.2.15", + "next": "14.2.8", "next-auth": "beta", "next-mdx-remote": "^4.4.1", "nextjs-toploader": "^3.7.15",