-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: fix dynamic import in rsc layout (#4445)
- Loading branch information
Showing
4 changed files
with
54 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 && <Spin fullscreen />} | ||
<FloatButton | ||
icon={<Icon icon={loading ? Loader2 : DatabaseIcon} spin={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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 && <Spin fullscreen />} | ||
<FloatButton | ||
icon={<Icon icon={loading ? Loader2 : DatabaseIcon} spin={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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters