nuxt-devtools-observatory 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, defineComponent, h, ref, watch, type VNode } from 'vue'
3
- import { useObservatoryData, type RenderEntry } from '../stores/observatory'
3
+ import { useObservatoryData, getObservatoryOrigin, type RenderEntry, type RenderEvent } from '../stores/observatory'
4
4
 
5
5
  interface ComponentNode {
6
6
  id: string
@@ -13,11 +13,13 @@ interface ComponentNode {
13
13
  mountCount: number
14
14
  avgMs: number
15
15
  triggers: string[]
16
+ timeline: RenderEvent[]
16
17
  children: ComponentNode[]
17
18
  parentId?: string
18
19
  parentLabel?: string
19
20
  isPersistent: boolean
20
21
  isHydrationMount: boolean
22
+ route: string
21
23
  }
22
24
 
23
25
  const TreeNode = defineComponent({
@@ -128,6 +130,20 @@ const TreeNode = defineComponent({
128
130
  )
129
131
  : null,
130
132
  h('span', { class: 'tree-metric-pill' }, `${metric} ${metricLabel}`),
133
+ node.file && node.file !== 'unknown'
134
+ ? h(
135
+ 'button',
136
+ {
137
+ class: 'tree-jump-btn',
138
+ title: `Open ${node.file} in editor`,
139
+ onClick: (e: MouseEvent) => {
140
+ e.stopPropagation()
141
+ openInEditor(node.file)
142
+ },
143
+ },
144
+ '↗'
145
+ )
146
+ : null,
131
147
  ]),
132
148
  ]
133
149
  ),
@@ -156,6 +172,8 @@ const TreeNode = defineComponent({
156
172
  const { renders, connected } = useObservatoryData()
157
173
 
158
174
  const activeMode = ref<'count' | 'time'>('count')
175
+ // Route filter — '' means show all routes
176
+ const activeRoute = ref('')
159
177
  // Separate thresholds per mode so switching modes doesn't produce nonsense results.
160
178
  // Count: flag components that rendered 3+ times (1 hydration mount is normal).
161
179
  // Time: flag components averaging 16ms+ (one animation frame budget).
@@ -222,10 +240,12 @@ function buildNodes(entries: RenderEntry[]) {
222
240
  mountCount: entry.mountCount ?? 1,
223
241
  avgMs: entry.avgMs,
224
242
  triggers: entry.triggers.map(formatTrigger),
243
+ timeline: entry.timeline ?? [],
225
244
  children: [],
226
245
  parentId: entry.parentUid !== undefined ? String(entry.parentUid) : undefined,
227
246
  isPersistent: Boolean(entry.isPersistent),
228
247
  isHydrationMount: Boolean(entry.isHydrationMount),
248
+ route: entry.route ?? '/',
229
249
  })
230
250
  }
231
251
 
@@ -392,11 +412,24 @@ function subtreeHasHotNode(node: ComponentNode): boolean {
392
412
  return isHot(node) || node.children.some((child) => subtreeHasHotNode(child))
393
413
  }
394
414
 
415
+ function nodeMatchesRoute(node: ComponentNode): boolean {
416
+ if (!activeRoute.value) return true
417
+ // A component is visible for a route if it was first seen on that route
418
+ // OR if any of its timeline events happened on that route.
419
+ if (node.route === activeRoute.value) return true
420
+ return node.timeline.some((e) => e.route === activeRoute.value)
421
+ }
422
+
423
+ function subtreeMatchesRoute(node: ComponentNode): boolean {
424
+ return nodeMatchesRoute(node) || node.children.some((child) => subtreeMatchesRoute(child))
425
+ }
426
+
395
427
  function isVisibleRoot(node: ComponentNode, searchTerm: string): boolean {
396
428
  const matchesCurrentSearch = treeMatches(node, searchTerm)
397
429
  const matchesCurrentHeat = !activeHotOnly.value || subtreeHasHotNode(node)
430
+ const matchesCurrentRoute = !activeRoute.value || subtreeMatchesRoute(node)
398
431
 
399
- return matchesCurrentSearch && matchesCurrentHeat
432
+ return matchesCurrentSearch && matchesCurrentHeat && matchesCurrentRoute
400
433
  }
401
434
 
402
435
  function pruneVisibleTree(node: ComponentNode, searchTerm: string): ComponentNode | null {
@@ -406,8 +439,9 @@ function pruneVisibleTree(node: ComponentNode, searchTerm: string): ComponentNod
406
439
 
407
440
  const matchesCurrentSearch = !searchTerm || matchesSearch(node, searchTerm) || visibleChildren.length > 0
408
441
  const matchesCurrentHeat = !activeHotOnly.value || isHot(node) || visibleChildren.length > 0
442
+ const matchesCurrentRoute = !activeRoute.value || nodeMatchesRoute(node) || visibleChildren.length > 0
409
443
 
410
- if (!matchesCurrentSearch || !matchesCurrentHeat) {
444
+ if (!matchesCurrentSearch || !matchesCurrentHeat || !matchesCurrentRoute) {
411
445
  return null
412
446
  }
413
447
 
@@ -459,6 +493,17 @@ const appEntries = computed(() =>
459
493
  }))
460
494
  )
461
495
 
496
+ const knownRoutes = computed(() => {
497
+ const routes = new Set<string>()
498
+ for (const node of allComponents.value) {
499
+ if (node.route) routes.add(node.route)
500
+ for (const event of node.timeline) {
501
+ if (event.route) routes.add(event.route)
502
+ }
503
+ }
504
+ return [...routes].sort()
505
+ })
506
+
462
507
  const activeSelected = computed(() => allComponents.value.find((node) => node.id === activeSelectedId.value) ?? null)
463
508
  const totalRenders = computed(() => allComponents.value.reduce((sum, node) => sum + node.rerenders + node.mountCount, 0))
464
509
  const hotCount = computed(() => allComponents.value.filter((node) => isHot(node)).length)
@@ -617,9 +662,25 @@ function basename(file: string) {
617
662
  )
618
663
  }
619
664
 
665
+ function openInEditor(file: string) {
666
+ if (!file || file === 'unknown') return
667
+ const origin = getObservatoryOrigin()
668
+ if (!origin) return
669
+ window.top?.postMessage({ type: 'observatory:open-in-editor', file }, origin)
670
+ }
671
+
620
672
  function pathLabel(node: ComponentNode) {
621
673
  return node.path.join(' / ')
622
674
  }
675
+
676
+ function formatMs(ms: number): string {
677
+ return ms < 1 ? '<1ms' : `${ms.toFixed(1)}ms`
678
+ }
679
+
680
+ function formatTimestamp(t: number): string {
681
+ // t is performance.now() — show as relative seconds from page load
682
+ return `+${(t / 1000).toFixed(2)}s`
683
+ }
623
684
  </script>
624
685
 
625
686
  <template>
@@ -642,6 +703,10 @@ function pathLabel(node: ComponentNode) {
642
703
  <span class="mono text-sm">{{ activeThreshold }}{{ activeMode === 'count' ? '+ renders' : 'ms+' }}</span>
643
704
  </div>
644
705
  <button :class="{ active: activeHotOnly }" @click="activeHotOnly = !activeHotOnly">hot only</button>
706
+ <select v-model="activeRoute" class="route-select mono text-sm" title="Filter by route">
707
+ <option value="">all routes</option>
708
+ <option v-for="r in knownRoutes" :key="r" :value="r">{{ r }}</option>
709
+ </select>
645
710
  <button :class="{ active: frozen }" style="margin-left: auto" @click="toggleFreeze">
646
711
  {{ frozen ? 'unfreeze' : 'freeze snapshot' }}
647
712
  </button>
@@ -744,7 +809,17 @@ function pathLabel(node: ComponentNode) {
744
809
  <span class="muted text-sm">path</span>
745
810
  <span class="mono text-sm">{{ pathLabel(activeSelected) }}</span>
746
811
  <span class="muted text-sm">file</span>
747
- <span class="mono text-sm muted">{{ activeSelected.file }}</span>
812
+ <span class="mono text-sm muted" style="display: flex; align-items: center; gap: 6px">
813
+ {{ activeSelected.file }}
814
+ <button
815
+ v-if="activeSelected.file && activeSelected.file !== 'unknown'"
816
+ class="jump-btn"
817
+ title="Open in editor"
818
+ @click="openInEditor(activeSelected.file)"
819
+ >
820
+ open ↗
821
+ </button>
822
+ </span>
748
823
  <span class="muted text-sm">file name</span>
749
824
  <span class="mono text-sm">{{ basename(activeSelected.file) }}</span>
750
825
  <span class="muted text-sm">parent</span>
@@ -778,6 +853,26 @@ function pathLabel(node: ComponentNode) {
778
853
  <div class="section-label">triggers</div>
779
854
  <div v-for="trigger in activeSelected.triggers" :key="trigger" class="trigger-item mono text-sm">{{ trigger }}</div>
780
855
  <div v-if="!activeSelected.triggers.length" class="muted text-sm">no triggers recorded</div>
856
+
857
+ <div class="section-label" style="margin-top: 8px">
858
+ render timeline
859
+ <span class="muted" style="font-weight: 400; text-transform: none; letter-spacing: 0">
860
+ ({{ activeSelected.timeline.length }})
861
+ </span>
862
+ </div>
863
+ <div v-if="!activeSelected.timeline.length" class="muted text-sm">no timeline events yet</div>
864
+ <div v-else class="timeline-list">
865
+ <div v-for="(event, idx) in [...activeSelected.timeline].reverse().slice(0, 30)" :key="idx" class="timeline-row">
866
+ <span class="timeline-kind mono" :class="event.kind">{{ event.kind }}</span>
867
+ <span class="timeline-time mono muted">{{ formatTimestamp(event.t) }}</span>
868
+ <span class="timeline-dur mono">{{ formatMs(event.durationMs) }}</span>
869
+ <span v-if="event.triggerKey" class="timeline-trigger mono muted">{{ event.triggerKey }}</span>
870
+ <span class="timeline-route mono muted" style="margin-left: auto">{{ event.route }}</span>
871
+ </div>
872
+ <div v-if="activeSelected.timeline.length > 30" class="muted text-sm" style="padding: 2px 0">
873
+ … {{ activeSelected.timeline.length - 30 }} earlier events
874
+ </div>
875
+ </div>
781
876
  </template>
782
877
  <div v-else class="detail-empty">click a component to inspect</div>
783
878
  </aside>
@@ -1153,6 +1248,123 @@ function pathLabel(node: ComponentNode) {
1153
1248
  color: var(--text2);
1154
1249
  }
1155
1250
 
1251
+ :deep(.tree-jump-btn) {
1252
+ display: none;
1253
+ padding: 0 4px;
1254
+ border: none;
1255
+ background: transparent;
1256
+ color: var(--text3);
1257
+ font-size: 11px;
1258
+ cursor: pointer;
1259
+ line-height: 1;
1260
+ flex-shrink: 0;
1261
+ }
1262
+
1263
+ :deep(.tree-row:hover .tree-jump-btn),
1264
+ :deep(.tree-row.selected .tree-jump-btn) {
1265
+ display: inline-flex;
1266
+ }
1267
+
1268
+ :deep(.tree-jump-btn:hover) {
1269
+ color: var(--teal);
1270
+ }
1271
+
1272
+ .jump-btn {
1273
+ font-size: 10px;
1274
+ padding: 1px 6px;
1275
+ border: 0.5px solid var(--border);
1276
+ border-radius: var(--radius);
1277
+ background: transparent;
1278
+ color: var(--text3);
1279
+ cursor: pointer;
1280
+ flex-shrink: 0;
1281
+ font-family: var(--mono);
1282
+ }
1283
+
1284
+ .jump-btn:hover {
1285
+ border-color: var(--teal);
1286
+ color: var(--teal);
1287
+ background: color-mix(in srgb, var(--teal) 8%, transparent);
1288
+ }
1289
+
1290
+ .route-select {
1291
+ padding: 3px 7px;
1292
+ border: 0.5px solid var(--border);
1293
+ border-radius: var(--radius);
1294
+ background: var(--bg2);
1295
+ color: var(--text);
1296
+ font-size: 11px;
1297
+ cursor: pointer;
1298
+ max-width: 140px;
1299
+ }
1300
+
1301
+ .timeline-list {
1302
+ display: flex;
1303
+ flex-direction: column;
1304
+ gap: 1px;
1305
+ background: var(--bg2);
1306
+ border-radius: var(--radius);
1307
+ padding: 4px 8px;
1308
+ max-height: 200px;
1309
+ overflow-y: auto;
1310
+ }
1311
+
1312
+ .timeline-row {
1313
+ display: flex;
1314
+ align-items: center;
1315
+ gap: 6px;
1316
+ padding: 2px 0;
1317
+ font-size: 11px;
1318
+ border-bottom: 0.5px solid var(--border);
1319
+ min-width: 0;
1320
+ }
1321
+
1322
+ .timeline-row:last-child {
1323
+ border-bottom: none;
1324
+ }
1325
+
1326
+ .timeline-kind {
1327
+ flex-shrink: 0;
1328
+ font-size: 10px;
1329
+ font-weight: 500;
1330
+ min-width: 40px;
1331
+ }
1332
+
1333
+ .timeline-kind.mount {
1334
+ color: var(--teal);
1335
+ }
1336
+
1337
+ .timeline-kind.update {
1338
+ color: var(--amber);
1339
+ }
1340
+
1341
+ .timeline-time {
1342
+ flex-shrink: 0;
1343
+ min-width: 52px;
1344
+ color: var(--text3);
1345
+ }
1346
+
1347
+ .timeline-dur {
1348
+ flex-shrink: 0;
1349
+ min-width: 38px;
1350
+ color: var(--text2);
1351
+ }
1352
+
1353
+ .timeline-trigger {
1354
+ overflow: hidden;
1355
+ text-overflow: ellipsis;
1356
+ white-space: nowrap;
1357
+ color: var(--text3);
1358
+ flex: 1;
1359
+ min-width: 0;
1360
+ }
1361
+
1362
+ .timeline-route {
1363
+ flex-shrink: 0;
1364
+ color: var(--text3);
1365
+ font-size: 10px;
1366
+ }
1367
+
1156
1368
  @media (max-width: 1180px) {
1157
1369
  .inspector {
1158
1370
  grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0 || ^4.0.0"
6
6
  },
7
- "version": "0.1.13",
7
+ "version": "0.1.15",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -362,7 +362,7 @@ function composableTrackerPlugin() {
362
362
  const args = path.node.arguments;
363
363
  const loc = path.node.loc;
364
364
  const meta = t.objectExpression([
365
- t.objectProperty(t.identifier("file"), t.stringLiteral(id.split("/").pop() ?? id)),
365
+ t.objectProperty(t.identifier("file"), t.stringLiteral(id)),
366
366
  t.objectProperty(t.identifier("line"), t.numericLiteral(loc?.start.line ?? 0))
367
367
  ]);
368
368
  path.replaceWith(
@@ -521,6 +521,9 @@ const module$1 = defineNuxtModule({
521
521
  if (!nuxt.options.dev) {
522
522
  return;
523
523
  }
524
+ if (!process.env.LAUNCH_EDITOR && !process.env.VITE_EDITOR) {
525
+ process.env.LAUNCH_EDITOR = "code";
526
+ }
524
527
  const resolver = createResolver(import.meta.url);
525
528
  nuxt.hook("vite:extendConfig", (config) => {
526
529
  const alias = config.resolve?.alias;
@@ -1,3 +1,15 @@
1
+ export interface RenderEvent {
2
+ /** 'mount' for initial mount, 'update' for reactive re-renders */
3
+ kind: 'mount' | 'update';
4
+ /** performance.now() timestamp */
5
+ t: number;
6
+ /** Duration in ms */
7
+ durationMs: number;
8
+ /** Reactive dep key that triggered this update, if known */
9
+ triggerKey?: string;
10
+ /** Route path this render happened on */
11
+ route: string;
12
+ }
1
13
  export interface RenderEntry {
2
14
  uid: number;
3
15
  name: string;
@@ -15,6 +27,8 @@ export interface RenderEntry {
15
27
  type: string;
16
28
  timestamp: number;
17
29
  }>;
30
+ /** Per-render timeline, capped at MAX_TIMELINE events (newest last) */
31
+ timeline: RenderEvent[];
18
32
  rect?: {
19
33
  x: number;
20
34
  y: number;
@@ -28,6 +42,8 @@ export interface RenderEntry {
28
42
  isPersistent: boolean;
29
43
  /** True if the first mount of this component happened during SSR hydration */
30
44
  isHydrationMount: boolean;
45
+ /** Route path this component was first seen on */
46
+ route: string;
31
47
  }
32
48
  /**
33
49
  * Sets up a render registry for tracking render-related metrics (e.g. rerenders, render time, etc.)
@@ -46,4 +62,5 @@ export declare function setupRenderRegistry(nuxtApp: {
46
62
  getAll: () => RenderEntry[];
47
63
  snapshot: () => RenderEntry[];
48
64
  reset: () => void;
65
+ setRoute: (path: string) => void;
49
66
  };
@@ -4,10 +4,15 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
4
4
  const pendingTriggeredRenders = /* @__PURE__ */ new Set();
5
5
  const renderStartTimes = /* @__PURE__ */ new Map();
6
6
  let preResetUids = /* @__PURE__ */ new Set();
7
+ let currentRoute = "/";
8
+ const MAX_TIMELINE = 100;
9
+ function setRoute(path) {
10
+ currentRoute = path;
11
+ }
7
12
  function ensureEntry(instance) {
8
13
  const uid = instance.$.uid;
9
14
  if (!entries.value.has(uid)) {
10
- entries.value.set(uid, makeEntry(uid, instance));
15
+ entries.value.set(uid, makeEntry(uid, instance, currentRoute));
11
16
  }
12
17
  return entries.value.get(uid);
13
18
  }
@@ -32,7 +37,7 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
32
37
  }
33
38
  renderStartTimes.set(uid, performance.now());
34
39
  }
35
- function recordRenderDuration(entry) {
40
+ function recordRenderDuration(entry, kind) {
36
41
  if (typeof performance === "undefined") {
37
42
  return;
38
43
  }
@@ -41,9 +46,22 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
41
46
  return;
42
47
  }
43
48
  renderStartTimes.delete(entry.uid);
44
- entry.totalMs += Math.max(performance.now() - startedAt, 0);
49
+ const durationMs = Math.max(performance.now() - startedAt, 0);
50
+ entry.totalMs += durationMs;
45
51
  const totalEvents = (entry.rerenders ?? 0) + Math.max(entry.mountCount, 1);
46
52
  entry.avgMs = Math.round(entry.totalMs / totalEvents * 10) / 10;
53
+ const lastTrigger = entry.triggers.length > 0 ? entry.triggers[entry.triggers.length - 1] : void 0;
54
+ const event = {
55
+ kind,
56
+ t: startedAt,
57
+ durationMs: Math.round(durationMs * 10) / 10,
58
+ triggerKey: kind === "update" && lastTrigger ? `${lastTrigger.type}: ${lastTrigger.key}` : void 0,
59
+ route: currentRoute
60
+ };
61
+ entry.timeline.push(event);
62
+ if (entry.timeline.length > MAX_TIMELINE) {
63
+ entry.timeline.shift();
64
+ }
47
65
  }
48
66
  function reset() {
49
67
  preResetUids = new Set(entries.value.keys());
@@ -54,6 +72,7 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
54
72
  entry.totalMs = 0;
55
73
  entry.avgMs = 0;
56
74
  entry.triggers = [];
75
+ entry.timeline = [];
57
76
  }
58
77
  }
59
78
  nuxtApp.vueApp.mixin({
@@ -73,7 +92,11 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
73
92
  entry.rerenders++;
74
93
  }
75
94
  syncRect(entry, this);
76
- recordRenderDuration(entry);
95
+ if (!entry.isPersistent || entry.mountCount === 1) {
96
+ recordRenderDuration(entry, "mount");
97
+ } else {
98
+ renderStartTimes.delete(entry.uid);
99
+ }
77
100
  emit("render:update", { uid: entry.uid, renders: entry.rerenders });
78
101
  },
79
102
  beforeUpdate() {
@@ -92,7 +115,7 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
92
115
  pendingTriggeredRenders.delete(entry.uid);
93
116
  entry.rerenders++;
94
117
  syncRect(entry, this);
95
- recordRenderDuration(entry);
118
+ recordRenderDuration(entry, "update");
96
119
  emit("render:update", { uid: entry.uid, renders: entry.rerenders });
97
120
  },
98
121
  unmounted() {
@@ -113,6 +136,7 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
113
136
  totalMs: entry.totalMs,
114
137
  avgMs: entry.avgMs,
115
138
  triggers: entry.triggers,
139
+ timeline: entry.timeline,
116
140
  rect: entry.rect ? {
117
141
  x: entry.rect.x,
118
142
  y: entry.rect.y,
@@ -123,7 +147,8 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
123
147
  } : void 0,
124
148
  parentUid: entry.parentUid,
125
149
  isPersistent: entry.isPersistent,
126
- isHydrationMount: entry.isHydrationMount
150
+ isHydrationMount: entry.isHydrationMount,
151
+ route: entry.route
127
152
  };
128
153
  }
129
154
  function getAll() {
@@ -139,9 +164,9 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
139
164
  const channel = window.__nuxt_devtools__?.channel;
140
165
  channel?.send(event, data);
141
166
  }
142
- return { getAll, snapshot, reset };
167
+ return { getAll, snapshot, reset, setRoute };
143
168
  }
144
- function makeEntry(uid, instance) {
169
+ function makeEntry(uid, instance, route) {
145
170
  const type = instance.$.type;
146
171
  const parentType = instance.$parent?.$?.type;
147
172
  const element = describeElement(instance.$el);
@@ -158,9 +183,11 @@ function makeEntry(uid, instance) {
158
183
  totalMs: 0,
159
184
  avgMs: 0,
160
185
  triggers: [],
186
+ timeline: [],
161
187
  parentUid: instance.$parent?.$.uid,
162
188
  isPersistent: false,
163
- isHydrationMount: false
189
+ isHydrationMount: false,
190
+ route
164
191
  };
165
192
  }
166
193
  function describeElement(el) {
@@ -87,6 +87,14 @@ export default defineNuxtPlugin(() => {
87
87
  const { id, key, value } = event.data;
88
88
  composableRegistry.editValue(id, key, value);
89
89
  }
90
+ if (type === "observatory:open-in-editor") {
91
+ const { file } = event.data;
92
+ if (file && file !== "unknown") {
93
+ const cleaned = file.replace(/^\/@fs/, "").replace(/\?.*$/, "");
94
+ fetch(`/__open-in-editor?file=${encodeURIComponent(cleaned)}`).catch(() => {
95
+ });
96
+ }
97
+ }
90
98
  });
91
99
  composableRegistry.onComposableChange(() => {
92
100
  if (!lastMessageSource || !lastMessageOrigin) {
@@ -118,6 +126,7 @@ export default defineNuxtPlugin(() => {
118
126
  );
119
127
  router.afterEach((to) => {
120
128
  composableRegistry.setRoute(to.path ?? "/");
129
+ renderRegistry.setRoute(to.path ?? "/");
121
130
  nextTick(() => broadcastAll());
122
131
  });
123
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-devtools-observatory",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Nuxt DevTools: useFetch Dashboard, provide/inject Graph, Composable Tracker, Render Heatmap",
5
5
  "type": "module",
6
6
  "main": "./dist/module.mjs",