Files
it-tools/src/components/MenuItemTooltip.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

78 lines
1.9 KiB
Vue

<script setup lang="ts">
import { RouterLink } from 'vue-router';
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
import type { Tool } from '@/tools/tools.types';
defineProps<{
tool: Tool;
}>();
const textRef = ref<HTMLElement>();
const showTooltip = ref(false);
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
// Must settle before the pointer arrives: n-tooltip reads `disabled` on enter,
// so deciding on hover would leave the first hover with a stale value.
async function checkTruncation() {
await nextTick();
const el = textRef.value;
if (el) {
// .menu-text is one nowrap ellipsised line, so overflow is exactly the condition.
// Replaces a canvas measureText() that cost a <canvas> + getComputedStyle per item.
showTooltip.value = el.scrollWidth > el.clientWidth;
}
}
function debouncedCheckTruncation() {
if (resizeTimeout) {
clearTimeout(resizeTimeout);
}
// Prevent the truncation check from running too frequently when the window is resized
resizeTimeout = setTimeout(checkTruncation, 500);
}
onMounted(() => {
checkTruncation();
window.addEventListener('resize', debouncedCheckTruncation);
});
onUnmounted(() => {
if (resizeTimeout) {
clearTimeout(resizeTimeout);
}
window.removeEventListener('resize', debouncedCheckTruncation);
});
</script>
<template>
<n-tooltip placement="right" :delay="500" :show-arrow="true" :disabled="!showTooltip">
<template #trigger>
<RouterLink :to="tool.path" class="menu-link">
<span ref="textRef" class="menu-text" @mouseenter="checkTruncation">
{{ tool.name }}
</span>
</RouterLink>
</template>
{{ tool.name }}
</n-tooltip>
</template>
<style scoped>
.menu-link {
display: block;
width: 100%;
text-decoration: none;
color: inherit;
}
.menu-text {
display: block;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>