perf(webui): code-split routes; cut initial JS from 606 kB to 284 kB
`vite build` was emitting a single ~606 kB chunk for the whole SPA
(Vite even printed its >500 kB warning). Every route — overview,
config (with its full edit-dialog form surface), logs, settings —
was eagerly imported in `router/index.tsx`, so users paid the full
parse + execute cost before the login redirect even resolved.
That's the most plausible cause of the "loading node config is
somewhat slow" report.
Switch each route to `lazyRouteComponent(() => import('…'), '<Name>')`
so the page chunk is fetched on demand, and wrap `<Outlet />` in
`AppLayout` with a `<Suspense>` boundary backed by a small skeleton
fallback. `defaultPreload: 'intent'` is already set on the router,
so hovering a sidebar link warms the next chunk before the click —
navigation still feels instant after the first idle moment.
Build now emits:
index.js 606 kB → 284 kB (-53%)
overview-page 15 kB
config-page 25 kB
logs-page 5.6 kB
settings-page 5.8 kB
button (shared primitives) 164 kB
+ smaller per-component chunks Vite shook out
And the >500 kB warning is gone.
Bonus: replace the per-render
`list.filter(...).map(...).includes(item.name)` O(n²) duplicate-name
check in `NetworkTabView` with a one-shot `Map<name, count>` —
matters every time the user types in the edit dialog and the tab
underneath re-renders.
This commit is contained in:
3 files changed
+65
-12
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useHookProcessOps } from '@/hooks/use-hook-process-ops';
|
||||
import { MainLayout } from '@/components/layout/main-layout';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { AppStateProvider } from '@/contexts/AppStateContext';
|
||||
import { useSession } from '@/contexts/SessionContext';
|
||||
import type { HookProcessInfo, QQInfo, SystemInfo } from '@/types';
|
||||
@@ -92,7 +93,13 @@ export function AppLayout() {
|
||||
}}
|
||||
>
|
||||
<MainLayout status={session.status} onLogout={handleLogout}>
|
||||
<Outlet />
|
||||
{/* Routes use `lazyRouteComponent` (router/index.tsx) for
|
||||
code-splitting, which suspends until the chunk is fetched.
|
||||
The chrome (sidebar / top bar) stays mounted across this
|
||||
boundary so only the page surface flashes a skeleton. */}
|
||||
<Suspense fallback={<PageFallback />}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
</MainLayout>
|
||||
|
||||
<ConfirmDialog
|
||||
@@ -116,3 +123,19 @@ export function AppLayout() {
|
||||
</AppStateProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function PageFallback() {
|
||||
// Generic page placeholder. Kept intentionally low-detail (just a
|
||||
// header + a couple of card-shaped blocks) so it works for every
|
||||
// route — overview's stat grid, config's tabbed editor, logs' list,
|
||||
// and the settings page all converge on roughly this skeleton on
|
||||
// their own loading states.
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-32" />
|
||||
<Skeleton className="h-32" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user