`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.
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
import {
|
|
createRootRoute,
|
|
createRoute,
|
|
createRouter,
|
|
lazyRouteComponent,
|
|
Outlet,
|
|
} from '@tanstack/react-router';
|
|
import { AppLayout } from './app-layout';
|
|
|
|
// Page components are loaded on demand so the initial paint only ships
|
|
// the auth surface + layout shell. With `defaultPreload: 'intent'` set
|
|
// below, the router warms the next chunk on hover/focus, so navigation
|
|
// still feels instant after the first idle moment. Previously every
|
|
// page (overview / config / logs / settings) lived in the single
|
|
// ~600 kB bundle that Vite explicitly warned about — config-page edit
|
|
// dialog alone pulls in a large form surface that most users never
|
|
// touch on first visit.
|
|
const rootRoute = createRootRoute({
|
|
component: () => <Outlet />,
|
|
});
|
|
|
|
const appLayoutRoute = createRoute({
|
|
id: 'app-layout',
|
|
getParentRoute: () => rootRoute,
|
|
component: AppLayout,
|
|
});
|
|
|
|
const overviewRoute = createRoute({
|
|
path: '/',
|
|
getParentRoute: () => appLayoutRoute,
|
|
component: lazyRouteComponent(
|
|
() => import('@/components/pages/overview-page'),
|
|
'OverviewPage',
|
|
),
|
|
});
|
|
|
|
const configRoute = createRoute({
|
|
path: '/config',
|
|
getParentRoute: () => appLayoutRoute,
|
|
component: lazyRouteComponent(
|
|
() => import('@/components/pages/config-page'),
|
|
'ConfigPage',
|
|
),
|
|
});
|
|
|
|
const logsRoute = createRoute({
|
|
path: '/logs',
|
|
getParentRoute: () => appLayoutRoute,
|
|
component: lazyRouteComponent(
|
|
() => import('@/components/pages/logs-page'),
|
|
'LogsPage',
|
|
),
|
|
});
|
|
|
|
const settingsRoute = createRoute({
|
|
path: '/settings',
|
|
getParentRoute: () => appLayoutRoute,
|
|
component: lazyRouteComponent(
|
|
() => import('@/components/pages/settings-page'),
|
|
'SettingsPage',
|
|
),
|
|
});
|
|
|
|
const routeTree = rootRoute.addChildren([
|
|
appLayoutRoute.addChildren([overviewRoute, configRoute, logsRoute, settingsRoute]),
|
|
]);
|
|
|
|
export const appRouter = createRouter({
|
|
routeTree,
|
|
defaultPreload: 'intent',
|
|
});
|
|
|
|
declare module '@tanstack/react-router' {
|
|
interface Register {
|
|
router: typeof appRouter;
|
|
}
|
|
}
|
|
|
|
/** Paths registered on the layout — single source of truth for nav metadata. */
|
|
export type AppPath = '/' | '/config' | '/logs' | '/settings';
|