mirror of https://github.com/buster-so/buster.git
lazy load dev tools
This commit is contained in:
parent
4b16bfff29
commit
4058a80141
|
@ -1,5 +1,5 @@
|
||||||
import type { ErrorRouteComponent } from '@tanstack/react-router';
|
import type { ErrorRouteComponent } from '@tanstack/react-router';
|
||||||
import { lazy, Suspense } from 'react';
|
import { lazy, Suspense, useEffect, useState } from 'react';
|
||||||
|
|
||||||
// Lazy load the GlobalErrorCard component
|
// Lazy load the GlobalErrorCard component
|
||||||
const GlobalErrorCard = lazy(() =>
|
const GlobalErrorCard = lazy(() =>
|
||||||
|
@ -13,6 +13,19 @@ const ErrorLoadingFallback = () => <div />;
|
||||||
|
|
||||||
// Wrapper component that handles lazy loading with Suspense
|
// Wrapper component that handles lazy loading with Suspense
|
||||||
export const LazyGlobalErrorCard: ErrorRouteComponent = (props) => {
|
export const LazyGlobalErrorCard: ErrorRouteComponent = (props) => {
|
||||||
|
// Track if we're on the client side
|
||||||
|
const [isClient, setIsClient] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Set to true only after mount (client-side only)
|
||||||
|
setIsClient(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// During SSR, render the fallback directly to avoid hydration mismatch
|
||||||
|
if (!isClient) {
|
||||||
|
return <ErrorLoadingFallback />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<ErrorLoadingFallback />}>
|
<Suspense fallback={<ErrorLoadingFallback />}>
|
||||||
<GlobalErrorCard {...props} />
|
<GlobalErrorCard {...props} />
|
||||||
|
|
|
@ -5,7 +5,7 @@ import * as React from 'react';
|
||||||
import { Xmark } from '@/components/ui/icons';
|
import { Xmark } from '@/components/ui/icons';
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { Button } from '../buttons';
|
import { Button } from '../buttons/Button';
|
||||||
|
|
||||||
const Dialog = DialogPrimitive.Root;
|
const Dialog = DialogPrimitive.Root;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type React from 'react';
|
||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
import { type ExternalToast, toast } from 'sonner';
|
import { type ExternalToast, toast } from 'sonner';
|
||||||
import { createContext, useContextSelector } from 'use-context-selector';
|
import { createContext, useContextSelector } from 'use-context-selector';
|
||||||
// import { ConfirmModal } from '@/components/ui/modal/ConfirmModal';
|
import { ConfirmModal } from '@/components/ui/modal/ConfirmModal';
|
||||||
import { Toaster } from '@/components/ui/toaster/Toaster';
|
import { Toaster } from '@/components/ui/toaster/Toaster';
|
||||||
import { useOpenConfirmModal } from './useConfirmModal';
|
import { useOpenConfirmModal } from './useConfirmModal';
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ export const BusterNotificationsProvider: React.FC<PropsWithChildren> = ({ child
|
||||||
<BusterNotifications.Provider value={{ ...value, openConfirmModal }}>
|
<BusterNotifications.Provider value={{ ...value, openConfirmModal }}>
|
||||||
{children}
|
{children}
|
||||||
<Toaster />
|
<Toaster />
|
||||||
{/* <ConfirmModal {...confirmModalProps} /> */}
|
<ConfirmModal {...confirmModalProps} />
|
||||||
</BusterNotifications.Provider>
|
</BusterNotifications.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { TanstackDevtools as TanstackDevtoolsBase } from '@tanstack/react-devtools';
|
||||||
|
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools';
|
||||||
|
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools';
|
||||||
|
import type React from 'react';
|
||||||
|
import StoreDevtools from './demo-store-devtools';
|
||||||
|
|
||||||
|
// The actual devtools component implementation
|
||||||
|
const TanstackDevtoolsImpl: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<TanstackDevtoolsBase
|
||||||
|
config={{
|
||||||
|
position: 'bottom-left',
|
||||||
|
hideUntilHover: true,
|
||||||
|
defaultOpen: false,
|
||||||
|
}}
|
||||||
|
plugins={[
|
||||||
|
{
|
||||||
|
name: 'Tanstack Query',
|
||||||
|
render: <ReactQueryDevtoolsPanel />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tanstack Router',
|
||||||
|
render: <TanStackRouterDevtoolsPanel />,
|
||||||
|
},
|
||||||
|
StoreDevtools,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TanstackDevtoolsImpl;
|
|
@ -1,28 +1,37 @@
|
||||||
import { TanstackDevtools as TanstackDevtoolsBase } from '@tanstack/react-devtools';
|
|
||||||
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools';
|
|
||||||
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools';
|
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import StoreDevtools from './demo-store-devtools';
|
import { lazy, Suspense, useEffect, useState } from 'react';
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
|
||||||
|
// Lazy load the actual devtools component
|
||||||
|
const LazyTanstackDevtools = lazy(() =>
|
||||||
|
import('./tanstack-devtools-impl').then((mod) => ({
|
||||||
|
default: mod.default,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Export component with Suspense wrapper
|
||||||
export const TanstackDevtools: React.FC = () => {
|
export const TanstackDevtools: React.FC = () => {
|
||||||
|
// Track if we're on the client side
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
const [useDevTools, setUseDevTools] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Set to true only after mount (client-side only)
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useHotkeys('shift+alt+d', () => {
|
||||||
|
setUseDevTools(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only render in development and on the client
|
||||||
|
if (!mounted || !useDevTools) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TanstackDevtoolsBase
|
<Suspense fallback={null}>
|
||||||
config={{
|
<LazyTanstackDevtools />
|
||||||
position: 'bottom-left',
|
</Suspense>
|
||||||
hideUntilHover: true,
|
|
||||||
defaultOpen: false,
|
|
||||||
}}
|
|
||||||
plugins={[
|
|
||||||
{
|
|
||||||
name: 'Tanstack Query',
|
|
||||||
render: <ReactQueryDevtoolsPanel />,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Tanstack Router',
|
|
||||||
render: <TanStackRouterDevtoolsPanel />,
|
|
||||||
},
|
|
||||||
StoreDevtools,
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,6 +35,22 @@ const config = defineConfig({
|
||||||
if (id.includes('node_modules/@supabase')) {
|
if (id.includes('node_modules/@supabase')) {
|
||||||
return 'vendor-supabase';
|
return 'vendor-supabase';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id.includes('components/ui/icons')) {
|
||||||
|
return 'vendor-icons';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('components/ui')) {
|
||||||
|
return 'vendor-ui';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('zod')) {
|
||||||
|
return 'vendor-zod';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('@tanstack')) {
|
||||||
|
return 'vendor-tanstack';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue