refactor(web): use standardized Loader pattern for TanStack devtools

This commit is contained in:
yyh 2025-12-29 16:09:17 +08:00
parent 04648fc99a
commit bb5a654f8d
No known key found for this signature in database
4 changed files with 26 additions and 16 deletions

View File

@ -1,3 +1,2 @@
export { ReactScan } from './react-scan'
export { ReactScanLoader } from './react-scan'
export { TanStackDevtoolsWrapper } from './tanstack'
export * from './react-scan'
export * from './tanstack'

View File

@ -1 +1,2 @@
export { TanStackDevtoolsWrapper } from './devtools'
export { TanStackDevtoolsLoader } from './loader'

View File

@ -0,0 +1,21 @@
'use client'
import { lazy, Suspense } from 'react'
import { IS_DEV } from '@/config'
const TanStackDevtoolsWrapper = lazy(() =>
import('./devtools').then(module => ({
default: module.TanStackDevtoolsWrapper,
})),
)
export const TanStackDevtoolsLoader = () => {
if (!IS_DEV)
return null
return (
<Suspense fallback={null}>
<TanStackDevtoolsWrapper />
</Suspense>
)
}

View File

@ -2,14 +2,7 @@
import type { FC, PropsWithChildren } from 'react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { lazy, Suspense } from 'react'
import { IS_DEV } from '@/config'
const TanStackDevtoolsWrapper = lazy(() =>
import('@/app/components/devtools/tanstack').then(module => ({
default: module.TanStackDevtoolsWrapper,
})),
)
import { TanStackDevtoolsLoader } from '@/app/components/devtools'
const STALE_TIME = 1000 * 60 * 30 // 30 minutes
@ -26,11 +19,7 @@ export const TanstackQueryInitializer: FC<PropsWithChildren> = (props) => {
return (
<QueryClientProvider client={client}>
{children}
{IS_DEV && (
<Suspense fallback={null}>
<TanStackDevtoolsWrapper />
</Suspense>
)}
<TanStackDevtoolsLoader />
</QueryClientProvider>
)
}