Files
it-tools/src/App.vue
T
641fa857b4 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 <canvas> 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) <noreply@anthropic.com>

* Fix small width in mermaid exporter

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: sharevb <sharevb@gmail.com>
2026-09-27 12:04:23 +02:00

130 lines
3.5 KiB
Vue

<script setup lang="ts">
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';
import { getITToolsSetting } from './composable/queryParams';
const route = useRoute();
const layout = computed(() => route?.meta?.layout ?? layouts.base);
const styleStore = useStyleStore();
const theme = computed(() => (styleStore.isDarkTheme ? darkTheme : null));
const themeOverrides = computed(() => (styleStore.isDarkTheme ? darkThemeOverrides : lightThemeOverrides));
const { locale } = useI18n();
const colorPalette = useAppTheme();
// Create CSS custom properties for the color palette
const cssVars = computed(() => ({
'--loading-background-color': colorPalette.value.loading_background,
}));
// Apply CSS variables to the document root - batch updates to avoid thrashing
let pendingCssUpdate = false;
watchEffect(() => {
if (pendingCssUpdate) {
return;
}
pendingCssUpdate = true;
requestAnimationFrame(() => {
const root = document.documentElement;
Object.entries(cssVars.value).forEach(([key, value]) => {
root.style.setProperty(key, value);
});
pendingCssUpdate = false;
});
});
locale.value = get(getITToolsSetting('default_locale', locale.value));
syncRef(locale, useStorage('locale', locale));
</script>
<template>
<n-config-provider :theme="theme" :theme-overrides="themeOverrides">
<NGlobalStyle />
<NMessageProvider placement="bottom">
<NNotificationProvider placement="bottom-right">
<div class="app-root">
<!-- Wraps the switch: inside it, this is to prevent moving between a plain and a tool route
tearing down down the sider and remounted its ~460 menu items. -->
<BaseLayout>
<component :is="layout">
<RouterView />
</component>
</BaseLayout>
</div>
</NNotificationProvider>
</NMessageProvider>
</n-config-provider>
</template>
<style>
html {
height: 100%;
margin: 0;
padding: 0;
backface-visibility: hidden;
-webkit-font-smoothing: antialiased;
-webkit-backface-visibility: hidden;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
/* The document scrolls vertically (see MenuLayout.vue); never horizontally */
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
}
* {
box-sizing: border-box;
}
/* No transform/contain here: they would make .app-root the containing block
for position:fixed descendants (the mobile menu), and the old inner-scroll
perf rationale no longer applies now that the document is the scroller. */
.app-root {
-webkit-overflow-scrolling: touch;
}
body .vld-container {
position: absolute;
left: 0;
top: 0;
width: 100%;
background-color: var(--loading-background-color);
text-align: center;
pointer-events: none;
}
/* Fullscreen fallback: overlay mounted on <body> (first navigation) */
body > .vld-container {
height: 100vh;
z-index: 9999;
}
/* Route-change overlay scoped to the page area (see router.ts) */
.page-content > .vld-container {
height: 100%;
min-height: 350px;
z-index: 100;
}
body .vld-container.vl-active {
pointer-events: auto;
}
body .vld-container .vl-overlay.vl-active {
margin-top: 15%;
}
</style>