nuxt-devtools-observatory 0.1.19 → 0.1.20
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.
- package/client/.env +1 -0
- package/client/.env.example +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -2
- package/dist/runtime/composables/render-registry.js +33 -4
- package/package.json +1 -1
package/client/.env
CHANGED
package/client/.env.example
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -385,11 +385,13 @@ function composableTrackerPlugin() {
|
|
|
385
385
|
const importLine = `import { __trackComposable } from 'nuxt-devtools-observatory/runtime/composable-registry';
|
|
386
386
|
`;
|
|
387
387
|
const output = generate(ast, { retainLines: true }, scriptCode);
|
|
388
|
+
const alreadyImported = output.code.includes("nuxt-devtools-observatory/runtime/composable-registry");
|
|
389
|
+
const prefix = alreadyImported ? "" : importLine;
|
|
388
390
|
let finalCode;
|
|
389
391
|
if (isVue) {
|
|
390
|
-
finalCode = code.slice(0, scriptStart) +
|
|
392
|
+
finalCode = code.slice(0, scriptStart) + prefix + output.code + code.slice(scriptStart + scriptCode.length);
|
|
391
393
|
} else {
|
|
392
|
-
finalCode =
|
|
394
|
+
finalCode = prefix + output.code;
|
|
393
395
|
}
|
|
394
396
|
return { code: finalCode, map: output.map };
|
|
395
397
|
} catch (err) {
|
|
@@ -3,7 +3,9 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
3
3
|
const pendingTriggeredRenders = /* @__PURE__ */ new Set();
|
|
4
4
|
const renderStartTimes = /* @__PURE__ */ new Map();
|
|
5
5
|
let currentRoute = "/";
|
|
6
|
-
const
|
|
6
|
+
const hasEnv = typeof import.meta.env !== "undefined" && import.meta.env !== void 0;
|
|
7
|
+
const MAX_TIMELINE = hasEnv && import.meta.env?.VITE_OBSERVATORY_MAX_RENDER_TIMELINE ? Number(import.meta.env.VITE_OBSERVATORY_MAX_RENDER_TIMELINE) : 100;
|
|
8
|
+
const HIDE_INTERNALS = hasEnv && import.meta.env?.VITE_OBSERVATORY_HEATMAP_HIDE_INTERNALS !== void 0 ? import.meta.env.VITE_OBSERVATORY_HEATMAP_HIDE_INTERNALS === "true" : false;
|
|
7
9
|
let dirty = true;
|
|
8
10
|
let cachedSnapshot = "[]";
|
|
9
11
|
function markDirty() {
|
|
@@ -12,10 +14,28 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
12
14
|
function setRoute(path) {
|
|
13
15
|
currentRoute = path;
|
|
14
16
|
}
|
|
17
|
+
function isInternalInstance(instance) {
|
|
18
|
+
const file = instance.$.type.__file;
|
|
19
|
+
return !file || file.includes("node_modules");
|
|
20
|
+
}
|
|
21
|
+
function nearestTrackedAncestorUid(instance) {
|
|
22
|
+
let cursor = instance.$parent;
|
|
23
|
+
while (cursor) {
|
|
24
|
+
if (!isInternalInstance(cursor)) {
|
|
25
|
+
return cursor.$.uid;
|
|
26
|
+
}
|
|
27
|
+
cursor = cursor.$parent;
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
15
31
|
function ensureEntry(instance) {
|
|
16
32
|
const uid = instance.$.uid;
|
|
17
33
|
if (!entries.has(uid)) {
|
|
18
|
-
|
|
34
|
+
if (HIDE_INTERNALS && isInternalInstance(instance)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const parentUid = HIDE_INTERNALS ? nearestTrackedAncestorUid(instance) : instance.$parent?.$.uid;
|
|
38
|
+
entries.set(uid, makeEntry(uid, instance, currentRoute, parentUid));
|
|
19
39
|
markDirty();
|
|
20
40
|
}
|
|
21
41
|
return entries.get(uid);
|
|
@@ -111,6 +131,9 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
111
131
|
},
|
|
112
132
|
mounted() {
|
|
113
133
|
const entry = ensureEntry(this);
|
|
134
|
+
if (!entry) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
114
137
|
entry.mountCount++;
|
|
115
138
|
const isHydration = options.isHydrating?.() ?? false;
|
|
116
139
|
if (isHydration && entry.mountCount === 1) {
|
|
@@ -133,6 +156,9 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
133
156
|
},
|
|
134
157
|
renderTriggered({ key, type }) {
|
|
135
158
|
const entry = ensureEntry(this);
|
|
159
|
+
if (!entry) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
136
162
|
entry.triggers.push({ key: String(key), type, timestamp: performance.now() });
|
|
137
163
|
pendingTriggeredRenders.add(entry.uid);
|
|
138
164
|
if (entry.triggers.length > 50) {
|
|
@@ -142,6 +168,9 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
142
168
|
},
|
|
143
169
|
updated() {
|
|
144
170
|
const entry = ensureEntry(this);
|
|
171
|
+
if (!entry) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
145
174
|
pendingTriggeredRenders.delete(entry.uid);
|
|
146
175
|
entry.rerenders++;
|
|
147
176
|
markRectDirty(entry.uid);
|
|
@@ -213,7 +242,7 @@ export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
|
213
242
|
}
|
|
214
243
|
return { getAll, getSnapshot, snapshot, reset, setRoute };
|
|
215
244
|
}
|
|
216
|
-
function makeEntry(uid, instance, route) {
|
|
245
|
+
function makeEntry(uid, instance, route, parentUid) {
|
|
217
246
|
const type = instance.$.type;
|
|
218
247
|
const parentType = instance.$parent?.$?.type;
|
|
219
248
|
const element = describeElement(instance.$el);
|
|
@@ -231,7 +260,7 @@ function makeEntry(uid, instance, route) {
|
|
|
231
260
|
avgMs: 0,
|
|
232
261
|
triggers: [],
|
|
233
262
|
timeline: [],
|
|
234
|
-
parentUid
|
|
263
|
+
parentUid,
|
|
235
264
|
isPersistent: false,
|
|
236
265
|
isHydrationMount: false,
|
|
237
266
|
route
|