From 641fa857b49140d2220efb06379322e10ca03ec8 Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Sun, 27 Sep 2026 12:04:23 +0200 Subject: [PATCH] perf(bundle): improve initial load + loading of tools (#575) * perf(bundle): improve initial load + loading of tool Render the sider once and only build the parts of it that are visible. - App.vue renders BaseLayout around the layout switch instead of inside each layout, so moving between a plain route and a tool route no longer unmounts and rebuilds the whole sider (~460 menu items) on every navigation. - CollapsibleToolMenu mounts a category's items the first time it opens. Every category starts collapsed, so the menu was built entirely out of view. - Its menuOptions computed no longer folds in the collapsed/active flags, which rebuilt every category's tools array -- and re-rendered every item -- per route change. They are read from the template instead. - MenuItemTooltip measures truncation with scrollWidth/clientWidth rather than a canvas measureText(), dropping a throwaway and a getComputedStyle per menu item. Production build, 3 runs each, fresh profile per run: first contentful paint 2476-2735ms -> 814-974ms main-thread blocking 1806-2024ms -> 250-294ms requests at boot 384 -> 208 click a tool from home 991-1014ms -> 178-197ms switch between tools 281-322ms -> 74-125ms Co-Authored-By: Claude Opus 5 (1M context) * Fix small width in mermaid exporter --------- Co-authored-by: Claude Opus 5 (1M context) Co-authored-by: sharevb --- src/App.vue | 11 +++- src/components/CollapsibleToolMenu.vue | 29 ++++++---- src/components/MenuItemTooltip.vue | 23 +++----- src/layouts/index.ts | 6 +- src/layouts/passthrough.layout.vue | 5 ++ src/layouts/tool.layout.vue | 79 +++++++++++++------------- 6 files changed, 81 insertions(+), 72 deletions(-) create mode 100644 src/layouts/passthrough.layout.vue diff --git a/src/App.vue b/src/App.vue index 401ae335..1400d811 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,6 +3,7 @@ import { RouterView, useRoute } from 'vue-router'; import { NGlobalStyle, NMessageProvider, NNotificationProvider, darkTheme } from 'naive-ui'; import { get } from '@vueuse/core'; import { darkThemeOverrides, lightThemeOverrides } from './themes'; +import BaseLayout from './layouts/base.layout.vue'; import { layouts } from './layouts'; import { useStyleStore } from './stores/style.store'; import { useAppTheme } from './ui/theme/themes'; @@ -52,9 +53,13 @@ syncRef(locale, useStorage('locale', locale));
- - - + + + + + +
diff --git a/src/components/CollapsibleToolMenu.vue b/src/components/CollapsibleToolMenu.vue index 66e9f208..045b36f6 100644 --- a/src/components/CollapsibleToolMenu.vue +++ b/src/components/CollapsibleToolMenu.vue @@ -47,6 +47,17 @@ watchEffect(() => { const isToggling = ref(false); const menuContainerRefs = ref>({}); +// Every category starts coMount a category's items when it first opens, then keep themllapsed, so mounting all ~460 items up front built a +// menu nobody can see. Mount a category's items when it first opens, then keep them. +const openedCategories = ref>({}); +watchEffect(() => { + toolsByCategory.value.forEach(({ name }) => { + if (collapsedCategories.value[name] === false) { + openedCategories.value[name] = true; + } + }); +}); + function toggleCategoryCollapse({ name }: { name: string }) { collapsedCategories.value[name] = !collapsedCategories.value[name]; } @@ -88,11 +99,12 @@ function isCategoryActive(components: Tool[]): boolean { return components.some((tool) => tool.path === route.path); } +// Depends on the tool list only: holding the collapsed/active flags in here rebuilt +// every category's `tools` array, re-rendering all ~460 items on each navigation. const menuOptions = computed(() => toolsByCategory.value.map(({ name, components }) => ({ name, - isCollapsed: collapsedCategories.value[name], - isActive: isCategoryActive(components), + components, animationDuration: getAnimationDuration(components.length), tools: components.map((tool) => ({ label: makeLabel(tool), @@ -155,14 +167,10 @@ const themeVars = useThemeVars(); -
+