lazy load dev tools

This commit is contained in:
Nate Kelley 2025-08-13 14:24:13 -06:00
parent 4b16bfff29
commit 4058a80141
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 95 additions and 26 deletions

View File

@ -1,5 +1,5 @@
import type { ErrorRouteComponent } from '@tanstack/react-router';
import { lazy, Suspense } from 'react';
import { lazy, Suspense, useEffect, useState } from 'react';
// Lazy load the GlobalErrorCard component
const GlobalErrorCard = lazy(() =>
@ -13,6 +13,19 @@ const ErrorLoadingFallback = () => <div />;
// Wrapper component that handles lazy loading with Suspense
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 (
<Suspense fallback={<ErrorLoadingFallback />}>
<GlobalErrorCard {...props} />

View File

@ -5,7 +5,7 @@ import * as React from 'react';
import { Xmark } from '@/components/ui/icons';
import { cn } from '@/lib/utils';
import { Button } from '../buttons';
import { Button } from '../buttons/Button';
const Dialog = DialogPrimitive.Root;

View File

@ -4,7 +4,7 @@ import type React from 'react';
import type { PropsWithChildren } from 'react';
import { type ExternalToast, toast } from 'sonner';
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 { useOpenConfirmModal } from './useConfirmModal';
@ -134,7 +134,7 @@ export const BusterNotificationsProvider: React.FC<PropsWithChildren> = ({ child
<BusterNotifications.Provider value={{ ...value, openConfirmModal }}>
{children}
<Toaster />
{/* <ConfirmModal {...confirmModalProps} /> */}
<ConfirmModal {...confirmModalProps} />
</BusterNotifications.Provider>
);
};

View File

@ -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;

View File

@ -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 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 = () => {
// 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 (
<TanstackDevtoolsBase
config={{
position: 'bottom-left',
hideUntilHover: true,
defaultOpen: false,
}}
plugins={[
{
name: 'Tanstack Query',
render: <ReactQueryDevtoolsPanel />,
},
{
name: 'Tanstack Router',
render: <TanStackRouterDevtoolsPanel />,
},
StoreDevtools,
]}
/>
<Suspense fallback={null}>
<LazyTanstackDevtools />
</Suspense>
);
};

View File

@ -35,6 +35,22 @@ const config = defineConfig({
if (id.includes('node_modules/@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';
}
},
},
},