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
@@ -353,6 +353,20 @@ function NetworkTabView({
|
||||
// widening cast at the call site rather than ladder-of-ifs per tab.
|
||||
const summarize = tab.summarize as (it: typeof list[number]) => string;
|
||||
|
||||
// Tally name occurrences once instead of doing `list.filter(...).map(...).includes(...)`
|
||||
// inside `.map()` (O(n²) per render). With this lookup, the duplicate
|
||||
// check is O(1) per row — matters once the list grows past a few entries
|
||||
// or when typing renames a node and the tab re-renders on every keystroke.
|
||||
const nameCounts = useMemo(() => {
|
||||
const counts = new Map<string, number>();
|
||||
for (const item of list) {
|
||||
const name = item.name;
|
||||
if (!name) continue;
|
||||
counts.set(name, (counts.get(name) ?? 0) + 1);
|
||||
}
|
||||
return counts;
|
||||
}, [list]);
|
||||
|
||||
if (list.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed py-16 text-muted-foreground">
|
||||
@@ -369,8 +383,7 @@ function NetworkTabView({
|
||||
<p className="text-xs text-muted-foreground">{tab.description}</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{list.map((item, idx) => {
|
||||
const others = list.filter((_, i) => i !== idx).map((n) => n.name);
|
||||
const duplicate = !!item.name && others.includes(item.name);
|
||||
const duplicate = !!item.name && (nameCounts.get(item.name) ?? 0) > 1;
|
||||
return (
|
||||
<NodeSummaryCard
|
||||
key={`${item.name}-${idx}`}
|
||||
|
||||
Reference in new issue
Block a user