@oxog/reactscope 1.0.0 → 1.1.0
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/README.md +47 -15
- package/dist/{chunk-IFCS6ABF.cjs → chunk-33CBEAOF.cjs} +106 -32
- package/dist/chunk-33CBEAOF.cjs.map +1 -0
- package/dist/{chunk-JESQX3XO.js → chunk-3Q6YBIBW.js} +28 -2
- package/dist/chunk-3Q6YBIBW.js.map +1 -0
- package/dist/{chunk-6L3WUS6V.cjs → chunk-6ALDCO2Q.cjs} +28 -2
- package/dist/chunk-6ALDCO2Q.cjs.map +1 -0
- package/dist/{chunk-4TZAECHG.cjs → chunk-7MVKPUC4.cjs} +5 -21
- package/dist/chunk-7MVKPUC4.cjs.map +1 -0
- package/dist/chunk-ACLEEAEC.cjs +83 -0
- package/dist/chunk-ACLEEAEC.cjs.map +1 -0
- package/dist/{chunk-LZO35OCP.js → chunk-AZ6OARKV.js} +2 -2
- package/dist/{chunk-LZO35OCP.js.map → chunk-AZ6OARKV.js.map} +1 -1
- package/dist/{chunk-KCUWALXE.cjs → chunk-C3IBGU7L.cjs} +5 -2
- package/dist/chunk-C3IBGU7L.cjs.map +1 -0
- package/dist/{chunk-M65L55OT.js → chunk-C4LJVRF5.js} +11 -8
- package/dist/chunk-C4LJVRF5.js.map +1 -0
- package/dist/{chunk-MPOQNCGP.js → chunk-E4PZKXY7.js} +5 -21
- package/dist/chunk-E4PZKXY7.js.map +1 -0
- package/dist/chunk-E7W2FVWO.js +78 -0
- package/dist/chunk-E7W2FVWO.js.map +1 -0
- package/dist/{chunk-H4W4UBLZ.cjs → chunk-EUYOAT56.cjs} +11 -8
- package/dist/chunk-EUYOAT56.cjs.map +1 -0
- package/dist/{chunk-RYAIO3BO.js → chunk-F3KDHISM.js} +5 -4
- package/dist/chunk-F3KDHISM.js.map +1 -0
- package/dist/{chunk-I427KZYN.cjs → chunk-KRRXA4SI.cjs} +2 -2
- package/dist/{chunk-I427KZYN.cjs.map → chunk-KRRXA4SI.cjs.map} +1 -1
- package/dist/{chunk-U2OPUU5R.js → chunk-MBFJ6ULY.js} +40 -18
- package/dist/chunk-MBFJ6ULY.js.map +1 -0
- package/dist/chunk-OMETOKM7.cjs +86 -0
- package/dist/chunk-OMETOKM7.cjs.map +1 -0
- package/dist/chunk-QT2GSPHP.js +21 -0
- package/dist/chunk-QT2GSPHP.js.map +1 -0
- package/dist/{chunk-OJGWFS55.cjs → chunk-U3TL6KFZ.cjs} +41 -19
- package/dist/chunk-U3TL6KFZ.cjs.map +1 -0
- package/dist/chunk-UQFSIGZW.cjs +24 -0
- package/dist/chunk-UQFSIGZW.cjs.map +1 -0
- package/dist/{chunk-6LHJL6MV.js → chunk-W7SGZQRF.js} +106 -32
- package/dist/chunk-W7SGZQRF.js.map +1 -0
- package/dist/{chunk-ZTO5ZZVE.js → chunk-XWZXCGPY.js} +5 -2
- package/dist/chunk-XWZXCGPY.js.map +1 -0
- package/dist/chunk-YG5FHHRH.js +80 -0
- package/dist/chunk-YG5FHHRH.js.map +1 -0
- package/dist/{chunk-QYMRRTSN.cjs → chunk-YL2LJ27D.cjs} +6 -5
- package/dist/chunk-YL2LJ27D.cjs.map +1 -0
- package/dist/index.cjs +428 -369
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -7
- package/dist/index.d.ts +33 -7
- package/dist/index.js +403 -343
- package/dist/index.js.map +1 -1
- package/dist/plugins/console-reporter/index.d.cts +1 -1
- package/dist/plugins/console-reporter/index.d.ts +1 -1
- package/dist/plugins/dashboard-ui/index.cjs +4 -3
- package/dist/plugins/dashboard-ui/index.d.cts +5 -1
- package/dist/plugins/dashboard-ui/index.d.ts +5 -1
- package/dist/plugins/dashboard-ui/index.js +2 -1
- package/dist/plugins/json-exporter/index.cjs +5 -3
- package/dist/plugins/json-exporter/index.d.cts +1 -1
- package/dist/plugins/json-exporter/index.d.ts +1 -1
- package/dist/plugins/json-exporter/index.js +3 -1
- package/dist/plugins/lifecycle-tracker/index.cjs +4 -3
- package/dist/plugins/lifecycle-tracker/index.d.cts +8 -1
- package/dist/plugins/lifecycle-tracker/index.d.ts +8 -1
- package/dist/plugins/lifecycle-tracker/index.js +2 -1
- package/dist/plugins/memory-tracker/index.d.cts +1 -1
- package/dist/plugins/memory-tracker/index.d.ts +1 -1
- package/dist/plugins/network-correlator/index.cjs +4 -4
- package/dist/plugins/network-correlator/index.d.cts +5 -1
- package/dist/plugins/network-correlator/index.d.ts +5 -1
- package/dist/plugins/network-correlator/index.js +2 -2
- package/dist/plugins/props-differ/index.cjs +4 -3
- package/dist/plugins/props-differ/index.d.cts +1 -1
- package/dist/plugins/props-differ/index.d.ts +1 -1
- package/dist/plugins/props-differ/index.js +2 -1
- package/dist/plugins/render-tracker/index.d.cts +1 -1
- package/dist/plugins/render-tracker/index.d.ts +1 -1
- package/dist/plugins/timeline-recorder/index.cjs +5 -4
- package/dist/plugins/timeline-recorder/index.d.cts +1 -1
- package/dist/plugins/timeline-recorder/index.d.ts +1 -1
- package/dist/plugins/timeline-recorder/index.js +3 -2
- package/dist/plugins/wasted-render-detector/index.cjs +4 -3
- package/dist/plugins/wasted-render-detector/index.d.cts +5 -8
- package/dist/plugins/wasted-render-detector/index.d.ts +5 -8
- package/dist/plugins/wasted-render-detector/index.js +2 -1
- package/dist/{types-DKPG_emi.d.ts → types-DNhmA1Tk.d.cts} +22 -1
- package/dist/{types-DKPG_emi.d.cts → types-DNhmA1Tk.d.ts} +22 -1
- package/package.json +20 -9
- package/dist/chunk-4TZAECHG.cjs.map +0 -1
- package/dist/chunk-6L3WUS6V.cjs.map +0 -1
- package/dist/chunk-6LHJL6MV.js.map +0 -1
- package/dist/chunk-H4W4UBLZ.cjs.map +0 -1
- package/dist/chunk-IFCS6ABF.cjs.map +0 -1
- package/dist/chunk-JESQX3XO.js.map +0 -1
- package/dist/chunk-KCUWALXE.cjs.map +0 -1
- package/dist/chunk-M65L55OT.js.map +0 -1
- package/dist/chunk-MPOQNCGP.js.map +0 -1
- package/dist/chunk-OJGWFS55.cjs.map +0 -1
- package/dist/chunk-QYMRRTSN.cjs.map +0 -1
- package/dist/chunk-RYAIO3BO.js.map +0 -1
- package/dist/chunk-U2OPUU5R.js.map +0 -1
- package/dist/chunk-ZTO5ZZVE.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYL2LJ27D_cjs = require('./chunk-YL2LJ27D.cjs');
|
|
4
4
|
var chunkDVRJ7PFB_cjs = require('./chunk-DVRJ7PFB.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var chunkU3TL6KFZ_cjs = require('./chunk-U3TL6KFZ.cjs');
|
|
6
|
+
var chunkKRRXA4SI_cjs = require('./chunk-KRRXA4SI.cjs');
|
|
7
7
|
var chunkQZ5T7HPO_cjs = require('./chunk-QZ5T7HPO.cjs');
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
8
|
+
var chunkC3IBGU7L_cjs = require('./chunk-C3IBGU7L.cjs');
|
|
9
|
+
var chunk7MVKPUC4_cjs = require('./chunk-7MVKPUC4.cjs');
|
|
10
|
+
var chunk6ALDCO2Q_cjs = require('./chunk-6ALDCO2Q.cjs');
|
|
11
|
+
require('./chunk-UQFSIGZW.cjs');
|
|
12
|
+
var chunk33CBEAOF_cjs = require('./chunk-33CBEAOF.cjs');
|
|
12
13
|
var chunkALGKN7FA_cjs = require('./chunk-ALGKN7FA.cjs');
|
|
13
14
|
var chunkWQRBHD23_cjs = require('./chunk-WQRBHD23.cjs');
|
|
14
|
-
var
|
|
15
|
+
var chunkEUYOAT56_cjs = require('./chunk-EUYOAT56.cjs');
|
|
16
|
+
require('./chunk-ACLEEAEC.cjs');
|
|
17
|
+
var chunkOMETOKM7_cjs = require('./chunk-OMETOKM7.cjs');
|
|
15
18
|
var React2 = require('react');
|
|
16
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
17
19
|
|
|
18
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
21
|
|
|
@@ -153,60 +155,6 @@ function createEventBus() {
|
|
|
153
155
|
return new EventBusImpl();
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
// src/utils/tree.ts
|
|
157
|
-
function createTree() {
|
|
158
|
-
return {
|
|
159
|
-
root: null,
|
|
160
|
-
nodeMap: /* @__PURE__ */ new Map()
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function createNode(id, name, metrics = null, depth = 0) {
|
|
164
|
-
return {
|
|
165
|
-
id,
|
|
166
|
-
name,
|
|
167
|
-
children: [],
|
|
168
|
-
metrics,
|
|
169
|
-
depth,
|
|
170
|
-
isExpanded: true
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function addChild(parent, child) {
|
|
174
|
-
const existingIndex = parent.children.findIndex((c) => c.id === child.id);
|
|
175
|
-
if (existingIndex !== -1) {
|
|
176
|
-
parent.children[existingIndex] = child;
|
|
177
|
-
} else {
|
|
178
|
-
parent.children.push(child);
|
|
179
|
-
}
|
|
180
|
-
child.depth = parent.depth + 1;
|
|
181
|
-
}
|
|
182
|
-
function removeNode(tree, nodeId) {
|
|
183
|
-
const node = tree.nodeMap.get(nodeId);
|
|
184
|
-
if (!node) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
for (const potentialParent of tree.nodeMap.values()) {
|
|
188
|
-
const childIndex = potentialParent.children.findIndex((c) => c.id === nodeId);
|
|
189
|
-
if (childIndex !== -1) {
|
|
190
|
-
potentialParent.children.splice(childIndex, 1);
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (tree.root?.id === nodeId) {
|
|
195
|
-
tree.root = null;
|
|
196
|
-
}
|
|
197
|
-
const removeDescendants = (n) => {
|
|
198
|
-
tree.nodeMap.delete(n.id);
|
|
199
|
-
for (const child of n.children) {
|
|
200
|
-
removeDescendants(child);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
removeDescendants(node);
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
function findNode(tree, nodeId) {
|
|
207
|
-
return tree.nodeMap.get(nodeId);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
158
|
// src/kernel/metrics-store.ts
|
|
211
159
|
function createDefaultMetrics(componentId, componentName) {
|
|
212
160
|
return {
|
|
@@ -230,7 +178,7 @@ function createDefaultMetrics(componentId, componentName) {
|
|
|
230
178
|
var MetricsStoreImpl = class {
|
|
231
179
|
constructor(maxHistorySize = 1e3) {
|
|
232
180
|
this.components = /* @__PURE__ */ new Map();
|
|
233
|
-
this.tree = createTree();
|
|
181
|
+
this.tree = chunkOMETOKM7_cjs.createTree();
|
|
234
182
|
this.timeline = [];
|
|
235
183
|
this.sessionStart = Date.now();
|
|
236
184
|
this.lastUpdate = Date.now();
|
|
@@ -248,7 +196,7 @@ var MetricsStoreImpl = class {
|
|
|
248
196
|
set(componentId, metrics) {
|
|
249
197
|
this.components.set(componentId, metrics);
|
|
250
198
|
this.lastUpdate = Date.now();
|
|
251
|
-
const node = findNode(this.tree, componentId);
|
|
199
|
+
const node = chunkOMETOKM7_cjs.findNode(this.tree, componentId);
|
|
252
200
|
if (node) {
|
|
253
201
|
node.metrics = metrics;
|
|
254
202
|
}
|
|
@@ -265,7 +213,7 @@ var MetricsStoreImpl = class {
|
|
|
265
213
|
}
|
|
266
214
|
this.components.set(componentId, updated);
|
|
267
215
|
this.lastUpdate = Date.now();
|
|
268
|
-
const node = findNode(this.tree, componentId);
|
|
216
|
+
const node = chunkOMETOKM7_cjs.findNode(this.tree, componentId);
|
|
269
217
|
if (node) {
|
|
270
218
|
node.metrics = updated;
|
|
271
219
|
}
|
|
@@ -276,7 +224,7 @@ var MetricsStoreImpl = class {
|
|
|
276
224
|
*/
|
|
277
225
|
delete(componentId) {
|
|
278
226
|
this.components.delete(componentId);
|
|
279
|
-
removeNode(this.tree, componentId);
|
|
227
|
+
chunkOMETOKM7_cjs.removeNode(this.tree, componentId);
|
|
280
228
|
this.lastUpdate = Date.now();
|
|
281
229
|
}
|
|
282
230
|
/**
|
|
@@ -290,7 +238,7 @@ var MetricsStoreImpl = class {
|
|
|
290
238
|
*/
|
|
291
239
|
clear() {
|
|
292
240
|
this.components.clear();
|
|
293
|
-
this.tree = createTree();
|
|
241
|
+
this.tree = chunkOMETOKM7_cjs.createTree();
|
|
294
242
|
this.timeline = [];
|
|
295
243
|
this.sessionStart = Date.now();
|
|
296
244
|
this.lastUpdate = Date.now();
|
|
@@ -303,36 +251,63 @@ var MetricsStoreImpl = class {
|
|
|
303
251
|
}
|
|
304
252
|
/**
|
|
305
253
|
* Update the component tree with a new component.
|
|
254
|
+
*
|
|
255
|
+
* React commits children before their parents, so a child can be reported
|
|
256
|
+
* before its parent node exists. Such children are kept as top-level nodes
|
|
257
|
+
* and adopted as soon as the parent is added.
|
|
306
258
|
*/
|
|
307
259
|
updateTree(componentId, componentName, parentId) {
|
|
308
|
-
let node = findNode(this.tree, componentId);
|
|
260
|
+
let node = chunkOMETOKM7_cjs.findNode(this.tree, componentId);
|
|
309
261
|
const metrics = this.components.get(componentId) ?? null;
|
|
310
262
|
if (!node) {
|
|
311
|
-
node = createNode(componentId, componentName, metrics);
|
|
263
|
+
node = chunkOMETOKM7_cjs.createNode(componentId, componentName, metrics);
|
|
312
264
|
this.tree.nodeMap.set(componentId, node);
|
|
313
265
|
} else {
|
|
314
266
|
node.name = componentName;
|
|
315
267
|
node.metrics = metrics;
|
|
316
268
|
}
|
|
317
|
-
if (parentId) {
|
|
318
|
-
const parentNode = findNode(this.tree, parentId);
|
|
269
|
+
if (parentId && parentId !== componentId) {
|
|
270
|
+
const parentNode = chunkOMETOKM7_cjs.findNode(this.tree, parentId);
|
|
319
271
|
if (parentNode) {
|
|
320
|
-
|
|
321
|
-
const componentMetrics = this.components.get(componentId);
|
|
322
|
-
if (componentMetrics) {
|
|
323
|
-
componentMetrics.parentId = parentId;
|
|
324
|
-
const parentMetrics = this.components.get(parentId);
|
|
325
|
-
if (parentMetrics && !parentMetrics.childIds.includes(componentId)) {
|
|
326
|
-
parentMetrics.childIds.push(componentId);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
272
|
+
this.attach(parentNode, node);
|
|
329
273
|
}
|
|
330
|
-
} else if (!this.tree.root) {
|
|
331
|
-
this.tree.root = node;
|
|
332
|
-
node.depth = 0;
|
|
333
274
|
}
|
|
275
|
+
for (const childMetrics of this.components.values()) {
|
|
276
|
+
if (childMetrics.parentId !== componentId || childMetrics.componentId === componentId) continue;
|
|
277
|
+
const childNode = chunkOMETOKM7_cjs.findNode(this.tree, childMetrics.componentId);
|
|
278
|
+
if (childNode && !node.children.includes(childNode)) {
|
|
279
|
+
this.attach(node, childNode);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
this.refreshRoot();
|
|
334
283
|
this.lastUpdate = Date.now();
|
|
335
284
|
}
|
|
285
|
+
attach(parentNode, node) {
|
|
286
|
+
chunkOMETOKM7_cjs.addChild(parentNode, node);
|
|
287
|
+
chunkOMETOKM7_cjs.setSubtreeDepth(node, parentNode.depth + 1);
|
|
288
|
+
const componentMetrics = this.components.get(node.id);
|
|
289
|
+
if (componentMetrics) {
|
|
290
|
+
componentMetrics.parentId = parentNode.id;
|
|
291
|
+
}
|
|
292
|
+
const parentMetrics = this.components.get(parentNode.id);
|
|
293
|
+
if (parentMetrics && !parentMetrics.childIds.includes(node.id)) {
|
|
294
|
+
parentMetrics.childIds.push(node.id);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Keep `tree.root` pointing at a top-level node that is still in the tree.
|
|
299
|
+
*/
|
|
300
|
+
refreshRoot() {
|
|
301
|
+
const root = this.tree.root;
|
|
302
|
+
if (root && this.tree.nodeMap.get(root.id) === root && root.depth === 0) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const first = chunkOMETOKM7_cjs.getRootNodes(this.tree)[0] ?? null;
|
|
306
|
+
if (first) {
|
|
307
|
+
chunkOMETOKM7_cjs.setSubtreeDepth(first, 0);
|
|
308
|
+
}
|
|
309
|
+
this.tree.root = first;
|
|
310
|
+
}
|
|
336
311
|
/**
|
|
337
312
|
* Remove a component from the tree.
|
|
338
313
|
*/
|
|
@@ -344,7 +319,8 @@ var MetricsStoreImpl = class {
|
|
|
344
319
|
parentMetrics.childIds = parentMetrics.childIds.filter((id) => id !== componentId);
|
|
345
320
|
}
|
|
346
321
|
}
|
|
347
|
-
removeNode(this.tree, componentId);
|
|
322
|
+
chunkOMETOKM7_cjs.removeNode(this.tree, componentId);
|
|
323
|
+
this.refreshRoot();
|
|
348
324
|
this.lastUpdate = Date.now();
|
|
349
325
|
}
|
|
350
326
|
/**
|
|
@@ -546,6 +522,13 @@ var DEFAULT_OPTIONS = {
|
|
|
546
522
|
sampleRate: 1,
|
|
547
523
|
maxHistorySize: 1e3
|
|
548
524
|
};
|
|
525
|
+
function toTimelineData(event) {
|
|
526
|
+
if (event.type === "metrics-update") {
|
|
527
|
+
const { renderHistory: _renderHistory, ...metrics } = event.metrics;
|
|
528
|
+
return { ...event, metrics };
|
|
529
|
+
}
|
|
530
|
+
return event;
|
|
531
|
+
}
|
|
549
532
|
var KernelImpl = class {
|
|
550
533
|
constructor(options = {}) {
|
|
551
534
|
this.destroyed = false;
|
|
@@ -606,10 +589,10 @@ var KernelImpl = class {
|
|
|
606
589
|
}
|
|
607
590
|
}
|
|
608
591
|
this.metricsStore.addTimelineEvent({
|
|
609
|
-
id:
|
|
592
|
+
id: chunkKRRXA4SI_cjs.uid(),
|
|
610
593
|
type: eventType,
|
|
611
594
|
timestamp: event.timestamp,
|
|
612
|
-
data: event
|
|
595
|
+
data: toTimelineData(event)
|
|
613
596
|
});
|
|
614
597
|
});
|
|
615
598
|
}
|
|
@@ -782,6 +765,9 @@ function getKernel() {
|
|
|
782
765
|
}
|
|
783
766
|
return globalKernel;
|
|
784
767
|
}
|
|
768
|
+
function getGlobalKernelIfSet() {
|
|
769
|
+
return globalKernel;
|
|
770
|
+
}
|
|
785
771
|
function setGlobalKernel(kernel) {
|
|
786
772
|
globalKernel = kernel;
|
|
787
773
|
}
|
|
@@ -803,6 +789,100 @@ function useScopeContextSafe() {
|
|
|
803
789
|
return React2.useContext(ScopeContext);
|
|
804
790
|
}
|
|
805
791
|
ScopeContext.displayName = "ScopeContext";
|
|
792
|
+
var ParentScopeContext = React2.createContext(null);
|
|
793
|
+
ParentScopeContext.displayName = "ReactScopeParent";
|
|
794
|
+
var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
795
|
+
var useIsomorphicLayoutEffect = canUseDOM ? React2.useLayoutEffect : React2.useEffect;
|
|
796
|
+
var now = typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : () => Date.now();
|
|
797
|
+
var scheduleMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => void Promise.resolve().then(fn);
|
|
798
|
+
var pendingUnmounts = /* @__PURE__ */ new Map();
|
|
799
|
+
function useMountTracking(kernel, componentId, componentName, parentId) {
|
|
800
|
+
useIsomorphicLayoutEffect(() => {
|
|
801
|
+
if (!kernel) return;
|
|
802
|
+
const pending = pendingUnmounts.get(componentId);
|
|
803
|
+
if (pending && pending.kernel === kernel) {
|
|
804
|
+
pendingUnmounts.delete(componentId);
|
|
805
|
+
} else {
|
|
806
|
+
const mountEvent = {
|
|
807
|
+
type: "mount",
|
|
808
|
+
timestamp: Date.now(),
|
|
809
|
+
componentId,
|
|
810
|
+
componentName,
|
|
811
|
+
parentId
|
|
812
|
+
};
|
|
813
|
+
kernel.emit(mountEvent);
|
|
814
|
+
}
|
|
815
|
+
return () => {
|
|
816
|
+
const entry = {
|
|
817
|
+
kernel,
|
|
818
|
+
emit: () => {
|
|
819
|
+
if (pendingUnmounts.get(componentId) !== entry) return;
|
|
820
|
+
pendingUnmounts.delete(componentId);
|
|
821
|
+
const unmountEvent = {
|
|
822
|
+
type: "unmount",
|
|
823
|
+
timestamp: Date.now(),
|
|
824
|
+
componentId,
|
|
825
|
+
componentName
|
|
826
|
+
};
|
|
827
|
+
kernel.emit(unmountEvent);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
pendingUnmounts.get(componentId)?.emit();
|
|
831
|
+
pendingUnmounts.set(componentId, entry);
|
|
832
|
+
scheduleMicrotask(entry.emit);
|
|
833
|
+
};
|
|
834
|
+
}, [kernel, componentId, componentName, parentId]);
|
|
835
|
+
}
|
|
836
|
+
var SUBSCRIPTION_INTERVAL_MS = 100;
|
|
837
|
+
function sameSnapshot(a, b) {
|
|
838
|
+
if (Object.is(a, b)) return true;
|
|
839
|
+
if (!(a instanceof Map) || !(b instanceof Map) || a.size !== b.size) return false;
|
|
840
|
+
for (const [key, value] of a) {
|
|
841
|
+
if (b.get(key) !== value) return false;
|
|
842
|
+
}
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
function useThrottledMetrics(kernel, read, matches, deps) {
|
|
846
|
+
const [value, setValue] = React2.useState(read);
|
|
847
|
+
const readRef = React2.useRef(read);
|
|
848
|
+
const matchesRef = React2.useRef(matches);
|
|
849
|
+
readRef.current = read;
|
|
850
|
+
matchesRef.current = matches;
|
|
851
|
+
React2.useEffect(() => {
|
|
852
|
+
if (!kernel) return;
|
|
853
|
+
let timer = null;
|
|
854
|
+
let lastFlush = 0;
|
|
855
|
+
let active = true;
|
|
856
|
+
const flush = () => {
|
|
857
|
+
timer = null;
|
|
858
|
+
if (!active) return;
|
|
859
|
+
lastFlush = Date.now();
|
|
860
|
+
setValue(readRef.current());
|
|
861
|
+
};
|
|
862
|
+
const latest = readRef.current();
|
|
863
|
+
setValue((previous) => sameSnapshot(previous, latest) ? previous : latest);
|
|
864
|
+
const unsubscribe = kernel.on("metrics-update", (event) => {
|
|
865
|
+
if (timer !== null || !matchesRef.current(event.componentId)) return;
|
|
866
|
+
const wait = Math.max(0, lastFlush + SUBSCRIPTION_INTERVAL_MS - Date.now());
|
|
867
|
+
timer = setTimeout(flush, wait);
|
|
868
|
+
});
|
|
869
|
+
return () => {
|
|
870
|
+
active = false;
|
|
871
|
+
unsubscribe();
|
|
872
|
+
if (timer !== null) clearTimeout(timer);
|
|
873
|
+
};
|
|
874
|
+
}, [kernel, ...deps]);
|
|
875
|
+
return value;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/react/provider.tsx
|
|
879
|
+
function registerAll(kernel, plugins) {
|
|
880
|
+
for (const plugin of plugins) {
|
|
881
|
+
if (kernel.getPlugin(plugin.name) !== plugin) {
|
|
882
|
+
kernel.register(plugin);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
806
886
|
function ReactScopeProvider({
|
|
807
887
|
children,
|
|
808
888
|
enabled = true,
|
|
@@ -810,24 +890,47 @@ function ReactScopeProvider({
|
|
|
810
890
|
onReady,
|
|
811
891
|
options = {}
|
|
812
892
|
}) {
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
}
|
|
830
|
-
const
|
|
893
|
+
const [state] = React2.useState(() => {
|
|
894
|
+
const kernel2 = createKernel({ enabled, ...options });
|
|
895
|
+
const core = [
|
|
896
|
+
chunkQZ5T7HPO_cjs.createRenderTrackerPlugin(),
|
|
897
|
+
chunkC3IBGU7L_cjs.createPropsDifferPlugin(),
|
|
898
|
+
chunk7MVKPUC4_cjs.createWastedRenderDetectorPlugin(),
|
|
899
|
+
chunk6ALDCO2Q_cjs.createLifecycleTrackerPlugin()
|
|
900
|
+
];
|
|
901
|
+
registerAll(kernel2, core);
|
|
902
|
+
return { kernel: kernel2, plugins: core };
|
|
903
|
+
});
|
|
904
|
+
const { kernel } = state;
|
|
905
|
+
const userPluginsRef = React2.useRef(null);
|
|
906
|
+
if (userPluginsRef.current === null) {
|
|
907
|
+
userPluginsRef.current = [...plugins];
|
|
908
|
+
registerAll(kernel, userPluginsRef.current);
|
|
909
|
+
}
|
|
910
|
+
const readyRef = React2.useRef(false);
|
|
911
|
+
const teardownRef = React2.useRef(null);
|
|
912
|
+
React2.useEffect(() => {
|
|
913
|
+
teardownRef.current = null;
|
|
914
|
+
const all = [...state.plugins, ...userPluginsRef.current ?? []];
|
|
915
|
+
registerAll(kernel, all);
|
|
916
|
+
setGlobalKernel(kernel);
|
|
917
|
+
return () => {
|
|
918
|
+
const teardown = () => {
|
|
919
|
+
if (teardownRef.current !== teardown) return;
|
|
920
|
+
teardownRef.current = null;
|
|
921
|
+
for (const plugin of [...all].reverse()) {
|
|
922
|
+
if (kernel.getPlugin(plugin.name) === plugin) {
|
|
923
|
+
kernel.unregister(plugin.name);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
if (getGlobalKernelIfSet() === kernel) {
|
|
927
|
+
setGlobalKernel(null);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
teardownRef.current = teardown;
|
|
931
|
+
scheduleMicrotask(teardown);
|
|
932
|
+
};
|
|
933
|
+
}, [kernel, state]);
|
|
831
934
|
React2.useEffect(() => {
|
|
832
935
|
if (enabled) {
|
|
833
936
|
kernel.enable();
|
|
@@ -835,86 +938,158 @@ function ReactScopeProvider({
|
|
|
835
938
|
kernel.disable();
|
|
836
939
|
}
|
|
837
940
|
}, [enabled, kernel]);
|
|
941
|
+
const { sampleRate, maxHistorySize, trackAllComponents } = options;
|
|
838
942
|
React2.useEffect(() => {
|
|
839
|
-
|
|
840
|
-
|
|
943
|
+
const next = {};
|
|
944
|
+
if (sampleRate !== void 0) next.sampleRate = sampleRate;
|
|
945
|
+
if (maxHistorySize !== void 0) next.maxHistorySize = maxHistorySize;
|
|
946
|
+
if (trackAllComponents !== void 0) next.trackAllComponents = trackAllComponents;
|
|
947
|
+
kernel.configure(next);
|
|
948
|
+
}, [kernel, sampleRate, maxHistorySize, trackAllComponents]);
|
|
841
949
|
React2.useEffect(() => {
|
|
842
|
-
if (
|
|
843
|
-
|
|
950
|
+
if (!readyRef.current && onReady) {
|
|
951
|
+
readyRef.current = true;
|
|
844
952
|
onReady(kernel);
|
|
845
953
|
}
|
|
846
954
|
}, [kernel, onReady]);
|
|
847
|
-
return
|
|
955
|
+
return React2__default.default.createElement(ScopeContext.Provider, { value: kernel }, children);
|
|
848
956
|
}
|
|
849
957
|
ReactScopeProvider.displayName = "ReactScopeProvider";
|
|
958
|
+
|
|
959
|
+
// src/utils/shallow-equal.ts
|
|
960
|
+
function shallowEqual(a, b) {
|
|
961
|
+
if (Object.is(a, b)) {
|
|
962
|
+
return true;
|
|
963
|
+
}
|
|
964
|
+
if (a == null || b == null) {
|
|
965
|
+
return a === b;
|
|
966
|
+
}
|
|
967
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
968
|
+
return a === b;
|
|
969
|
+
}
|
|
970
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
971
|
+
if (a.length !== b.length) {
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
for (let i = 0; i < a.length; i++) {
|
|
975
|
+
if (!Object.is(a[i], b[i])) {
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
981
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
const keysA = Object.keys(a);
|
|
985
|
+
const keysB = Object.keys(b);
|
|
986
|
+
if (keysA.length !== keysB.length) {
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
const objA = a;
|
|
990
|
+
const objB = b;
|
|
991
|
+
for (const key of keysA) {
|
|
992
|
+
if (!Object.prototype.hasOwnProperty.call(objB, key) || !Object.is(objA[key], objB[key])) {
|
|
993
|
+
return false;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/react/props.ts
|
|
1000
|
+
function diffProps(prev, next) {
|
|
1001
|
+
const changes = [];
|
|
1002
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
1003
|
+
for (const key of keys) {
|
|
1004
|
+
const prevValue = prev[key];
|
|
1005
|
+
const nextValue = next[key];
|
|
1006
|
+
if (!Object.is(prevValue, nextValue)) {
|
|
1007
|
+
changes.push({
|
|
1008
|
+
key,
|
|
1009
|
+
prev: prevValue,
|
|
1010
|
+
next: nextValue,
|
|
1011
|
+
isDeepEqual: shallowEqual(prevValue, nextValue)
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
return changes;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/react/hooks/use-scope.ts
|
|
850
1019
|
function useScope(name, options = {}) {
|
|
851
1020
|
const kernel = useScopeContextSafe();
|
|
1021
|
+
const parentId = React2.useContext(ParentScopeContext);
|
|
852
1022
|
const componentIdRef = React2.useRef(null);
|
|
853
1023
|
const renderCountRef = React2.useRef(0);
|
|
854
|
-
const
|
|
855
|
-
const
|
|
856
|
-
const
|
|
857
|
-
if (
|
|
858
|
-
componentIdRef.current =
|
|
1024
|
+
const committedRenderRef = React2.useRef(null);
|
|
1025
|
+
const prevPropsRef = React2.useRef(null);
|
|
1026
|
+
const optionsRef = React2.useRef(options);
|
|
1027
|
+
if (componentIdRef.current === null) {
|
|
1028
|
+
componentIdRef.current = chunkKRRXA4SI_cjs.uid();
|
|
859
1029
|
}
|
|
860
1030
|
const componentId = componentIdRef.current;
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
isMetricsUpdateRef.current = true;
|
|
875
|
-
setMetrics(event.metrics);
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
const mountEvent = {
|
|
879
|
-
type: "mount",
|
|
880
|
-
timestamp: now,
|
|
1031
|
+
const renderToken = {};
|
|
1032
|
+
const renderStart = now();
|
|
1033
|
+
useMountTracking(kernel, componentId, name, parentId);
|
|
1034
|
+
const readMetrics = () => kernel?.getMetrics().get(componentId);
|
|
1035
|
+
useIsomorphicLayoutEffect(() => {
|
|
1036
|
+
optionsRef.current = options;
|
|
1037
|
+
if (!kernel || committedRenderRef.current === renderToken) return;
|
|
1038
|
+
committedRenderRef.current = renderToken;
|
|
1039
|
+
const phase = renderCountRef.current === 0 ? "mount" : "update";
|
|
1040
|
+
renderCountRef.current++;
|
|
1041
|
+
const renderEvent = {
|
|
1042
|
+
type: "render",
|
|
1043
|
+
timestamp: Date.now(),
|
|
881
1044
|
componentId,
|
|
882
1045
|
componentName: name,
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
kernel.emit(mountEvent);
|
|
886
|
-
return () => {
|
|
887
|
-
unsubscribe();
|
|
888
|
-
const unmountEvent = {
|
|
889
|
-
type: "unmount",
|
|
890
|
-
timestamp: Date.now(),
|
|
891
|
-
componentId,
|
|
892
|
-
componentName: name
|
|
893
|
-
};
|
|
894
|
-
kernel.emit(unmountEvent);
|
|
1046
|
+
duration: now() - renderStart,
|
|
1047
|
+
phase
|
|
895
1048
|
};
|
|
896
|
-
|
|
1049
|
+
kernel.emit(renderEvent);
|
|
1050
|
+
if (options.trackProps && options.props) {
|
|
1051
|
+
const prevProps = prevPropsRef.current;
|
|
1052
|
+
prevPropsRef.current = { ...options.props };
|
|
1053
|
+
if (prevProps) {
|
|
1054
|
+
const changes = diffProps(prevProps, options.props);
|
|
1055
|
+
if (changes.length > 0) {
|
|
1056
|
+
kernel.emit({
|
|
1057
|
+
type: "props-change",
|
|
1058
|
+
timestamp: Date.now(),
|
|
1059
|
+
componentId,
|
|
1060
|
+
componentName: name,
|
|
1061
|
+
changes
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
if (options.onRender) {
|
|
1067
|
+
const metrics = kernel.getMetrics().get(componentId);
|
|
1068
|
+
if (metrics) {
|
|
1069
|
+
options.onRender(metrics);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
897
1073
|
const trackRender = React2.useCallback(
|
|
898
1074
|
(duration, phase) => {
|
|
899
1075
|
if (!kernel) return;
|
|
900
|
-
|
|
901
|
-
const renderEvent = {
|
|
1076
|
+
kernel.emit({
|
|
902
1077
|
type: "render",
|
|
903
1078
|
timestamp: Date.now(),
|
|
904
1079
|
componentId,
|
|
905
1080
|
componentName: name,
|
|
906
1081
|
duration,
|
|
907
1082
|
phase
|
|
908
|
-
};
|
|
909
|
-
|
|
910
|
-
if (
|
|
1083
|
+
});
|
|
1084
|
+
const onRender = optionsRef.current.onRender;
|
|
1085
|
+
if (onRender) {
|
|
911
1086
|
const currentMetrics = kernel.getMetrics().get(componentId);
|
|
912
1087
|
if (currentMetrics) {
|
|
913
|
-
|
|
1088
|
+
onRender(currentMetrics);
|
|
914
1089
|
}
|
|
915
1090
|
}
|
|
916
1091
|
},
|
|
917
|
-
[kernel, componentId, name
|
|
1092
|
+
[kernel, componentId, name]
|
|
918
1093
|
);
|
|
919
1094
|
const trackPropsChange = React2.useCallback(
|
|
920
1095
|
(changes) => {
|
|
@@ -929,45 +1104,21 @@ function useScope(name, options = {}) {
|
|
|
929
1104
|
},
|
|
930
1105
|
[kernel, componentId, name]
|
|
931
1106
|
);
|
|
932
|
-
|
|
933
|
-
if (isMetricsUpdateRef.current) {
|
|
934
|
-
isMetricsUpdateRef.current = false;
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
const currentRender = ++lastTrackedRenderRef.current;
|
|
938
|
-
const startTime = performance.now();
|
|
939
|
-
const phase = renderCountRef.current === 0 ? "mount" : "update";
|
|
940
|
-
if (typeof requestIdleCallback !== "undefined") {
|
|
941
|
-
requestIdleCallback(() => {
|
|
942
|
-
if (currentRender === lastTrackedRenderRef.current) {
|
|
943
|
-
const duration = performance.now() - startTime;
|
|
944
|
-
trackRender(duration, phase);
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
} else {
|
|
948
|
-
setTimeout(() => {
|
|
949
|
-
if (currentRender === lastTrackedRenderRef.current) {
|
|
950
|
-
const duration = performance.now() - startTime;
|
|
951
|
-
trackRender(duration, phase);
|
|
952
|
-
}
|
|
953
|
-
}, 0);
|
|
954
|
-
}
|
|
955
|
-
});
|
|
956
|
-
const handle = {
|
|
1107
|
+
return {
|
|
957
1108
|
get componentId() {
|
|
958
1109
|
return componentId;
|
|
959
1110
|
},
|
|
960
1111
|
get renderCount() {
|
|
961
|
-
return
|
|
1112
|
+
return readMetrics()?.renderCount ?? 0;
|
|
962
1113
|
},
|
|
963
1114
|
get lastRenderTime() {
|
|
964
|
-
return
|
|
1115
|
+
return readMetrics()?.lastRenderTime ?? 0;
|
|
965
1116
|
},
|
|
966
1117
|
get averageRenderTime() {
|
|
967
|
-
return
|
|
1118
|
+
return readMetrics()?.averageRenderTime ?? 0;
|
|
968
1119
|
},
|
|
969
1120
|
get wastedRenders() {
|
|
970
|
-
return
|
|
1121
|
+
return readMetrics()?.wastedRenderCount ?? 0;
|
|
971
1122
|
},
|
|
972
1123
|
get isTracking() {
|
|
973
1124
|
return kernel !== null && kernel.isEnabled();
|
|
@@ -975,44 +1126,27 @@ function useScope(name, options = {}) {
|
|
|
975
1126
|
trackRender,
|
|
976
1127
|
trackPropsChange
|
|
977
1128
|
};
|
|
978
|
-
return handle;
|
|
979
1129
|
}
|
|
1130
|
+
|
|
1131
|
+
// src/react/hooks/use-scope-metrics.ts
|
|
1132
|
+
var matchAll = () => true;
|
|
980
1133
|
function useScopeMetrics(componentId) {
|
|
981
1134
|
const kernel = useScopeContextSafe();
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
}, [kernel, componentId]);
|
|
990
|
-
React2.useEffect(() => {
|
|
991
|
-
if (!kernel) return;
|
|
992
|
-
updateMetrics();
|
|
993
|
-
const unsubscribe = kernel.on("metrics-update", (event) => {
|
|
994
|
-
if (event.componentId === componentId) {
|
|
995
|
-
setMetrics(event.metrics);
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
return unsubscribe;
|
|
999
|
-
}, [kernel, componentId, updateMetrics]);
|
|
1000
|
-
return metrics;
|
|
1135
|
+
return useThrottledMetrics(
|
|
1136
|
+
kernel,
|
|
1137
|
+
() => kernel?.getMetrics().get(componentId),
|
|
1138
|
+
(id) => id === componentId,
|
|
1139
|
+
[componentId]
|
|
1140
|
+
);
|
|
1001
1141
|
}
|
|
1002
1142
|
function useAllScopeMetrics() {
|
|
1003
1143
|
const kernel = useScopeContextSafe();
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
const unsubscribe = kernel.on("metrics-update", () => {
|
|
1011
|
-
setMetrics(new Map(kernel.getMetrics().getAll()));
|
|
1012
|
-
});
|
|
1013
|
-
return unsubscribe;
|
|
1014
|
-
}, [kernel]);
|
|
1015
|
-
return metrics;
|
|
1144
|
+
return useThrottledMetrics(
|
|
1145
|
+
kernel,
|
|
1146
|
+
() => kernel?.getMetrics().getAll() ?? /* @__PURE__ */ new Map(),
|
|
1147
|
+
matchAll,
|
|
1148
|
+
[]
|
|
1149
|
+
);
|
|
1016
1150
|
}
|
|
1017
1151
|
function useScopeSummary() {
|
|
1018
1152
|
const metrics = useAllScopeMetrics();
|
|
@@ -1031,174 +1165,87 @@ function useScopeSummary() {
|
|
|
1031
1165
|
averageRenderTime: totalRenders > 0 ? totalRenderTime / totalRenders : 0
|
|
1032
1166
|
};
|
|
1033
1167
|
}
|
|
1034
|
-
function Scope({
|
|
1035
|
-
children,
|
|
1036
|
-
name,
|
|
1037
|
-
onRender,
|
|
1038
|
-
trackProps: _trackProps = true
|
|
1039
|
-
}) {
|
|
1168
|
+
function Scope({ children, name, onRender }) {
|
|
1040
1169
|
const kernel = useScopeContextSafe();
|
|
1170
|
+
const parentId = React2.useContext(ParentScopeContext);
|
|
1041
1171
|
const componentIdRef = React2.useRef(null);
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1172
|
+
const onRenderRef = React2.useRef(onRender);
|
|
1173
|
+
onRenderRef.current = onRender;
|
|
1174
|
+
if (componentIdRef.current === null) {
|
|
1175
|
+
componentIdRef.current = chunkKRRXA4SI_cjs.uid();
|
|
1045
1176
|
}
|
|
1046
1177
|
const componentId = componentIdRef.current;
|
|
1047
1178
|
const componentName = name ?? "Scope";
|
|
1179
|
+
useMountTracking(kernel, componentId, componentName, parentId);
|
|
1048
1180
|
const handleRender = React2.useCallback(
|
|
1049
|
-
(_id, phase, actualDuration
|
|
1181
|
+
(_id, phase, actualDuration) => {
|
|
1050
1182
|
if (!kernel || !kernel.isEnabled()) return;
|
|
1051
|
-
if (!mountedRef.current) {
|
|
1052
|
-
mountedRef.current = true;
|
|
1053
|
-
const mountEvent = {
|
|
1054
|
-
type: "mount",
|
|
1055
|
-
timestamp: Date.now(),
|
|
1056
|
-
componentId,
|
|
1057
|
-
componentName,
|
|
1058
|
-
parentId: null
|
|
1059
|
-
};
|
|
1060
|
-
kernel.emit(mountEvent);
|
|
1061
|
-
}
|
|
1062
|
-
const renderPhase = phase === "mount" ? "mount" : "update";
|
|
1063
1183
|
const renderEvent = {
|
|
1064
1184
|
type: "render",
|
|
1065
1185
|
timestamp: Date.now(),
|
|
1066
1186
|
componentId,
|
|
1067
1187
|
componentName,
|
|
1068
1188
|
duration: actualDuration,
|
|
1069
|
-
phase:
|
|
1189
|
+
phase: phase === "mount" ? "mount" : "update"
|
|
1070
1190
|
};
|
|
1071
1191
|
kernel.emit(renderEvent);
|
|
1072
|
-
|
|
1192
|
+
const callback = onRenderRef.current;
|
|
1193
|
+
if (callback) {
|
|
1073
1194
|
const metrics = kernel.getMetrics().get(componentId);
|
|
1074
1195
|
if (metrics) {
|
|
1075
|
-
|
|
1196
|
+
callback(metrics);
|
|
1076
1197
|
}
|
|
1077
1198
|
}
|
|
1078
1199
|
},
|
|
1079
|
-
[kernel, componentId, componentName
|
|
1200
|
+
[kernel, componentId, componentName]
|
|
1201
|
+
);
|
|
1202
|
+
return React2__default.default.createElement(
|
|
1203
|
+
ParentScopeContext.Provider,
|
|
1204
|
+
{ value: componentId },
|
|
1205
|
+
React2__default.default.createElement(React2.Profiler, { id: componentId, onRender: handleRender }, children)
|
|
1080
1206
|
);
|
|
1081
|
-
React2__default.default.useEffect(() => {
|
|
1082
|
-
return () => {
|
|
1083
|
-
if (kernel && mountedRef.current) {
|
|
1084
|
-
const unmountEvent = {
|
|
1085
|
-
type: "unmount",
|
|
1086
|
-
timestamp: Date.now(),
|
|
1087
|
-
componentId,
|
|
1088
|
-
componentName
|
|
1089
|
-
};
|
|
1090
|
-
kernel.emit(unmountEvent);
|
|
1091
|
-
}
|
|
1092
|
-
};
|
|
1093
|
-
}, [kernel, componentId, componentName]);
|
|
1094
|
-
return /* @__PURE__ */ jsxRuntime.jsx(React2.Profiler, { id: componentId, onRender: handleRender, children });
|
|
1095
1207
|
}
|
|
1096
1208
|
Scope.displayName = "Scope";
|
|
1097
|
-
|
|
1098
|
-
// src/utils/shallow-equal.ts
|
|
1099
|
-
function shallowEqual(a, b) {
|
|
1100
|
-
if (Object.is(a, b)) {
|
|
1101
|
-
return true;
|
|
1102
|
-
}
|
|
1103
|
-
if (a == null || b == null) {
|
|
1104
|
-
return a === b;
|
|
1105
|
-
}
|
|
1106
|
-
if (typeof a !== "object" || typeof b !== "object") {
|
|
1107
|
-
return a === b;
|
|
1108
|
-
}
|
|
1109
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1110
|
-
if (a.length !== b.length) {
|
|
1111
|
-
return false;
|
|
1112
|
-
}
|
|
1113
|
-
for (let i = 0; i < a.length; i++) {
|
|
1114
|
-
if (!Object.is(a[i], b[i])) {
|
|
1115
|
-
return false;
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
return true;
|
|
1119
|
-
}
|
|
1120
|
-
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
1121
|
-
return false;
|
|
1122
|
-
}
|
|
1123
|
-
const keysA = Object.keys(a);
|
|
1124
|
-
const keysB = Object.keys(b);
|
|
1125
|
-
if (keysA.length !== keysB.length) {
|
|
1126
|
-
return false;
|
|
1127
|
-
}
|
|
1128
|
-
const objA = a;
|
|
1129
|
-
const objB = b;
|
|
1130
|
-
for (const key of keysA) {
|
|
1131
|
-
if (!Object.prototype.hasOwnProperty.call(objB, key) || !Object.is(objA[key], objB[key])) {
|
|
1132
|
-
return false;
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
return true;
|
|
1136
|
-
}
|
|
1137
1209
|
function withScope(WrappedComponent, options = {}) {
|
|
1138
|
-
const displayName = options.name
|
|
1210
|
+
const displayName = options.name || WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
1139
1211
|
const WithScopeComponent = React2.forwardRef((props, ref) => {
|
|
1140
1212
|
const kernel = useScopeContextSafe();
|
|
1213
|
+
const parentId = React2.useContext(ParentScopeContext);
|
|
1141
1214
|
const componentIdRef = React2.useRef(null);
|
|
1142
|
-
const
|
|
1215
|
+
const committedRenderRef = React2.useRef(null);
|
|
1143
1216
|
const prevPropsRef = React2.useRef(null);
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
componentIdRef.current = chunkI427KZYN_cjs.uid();
|
|
1217
|
+
if (componentIdRef.current === null) {
|
|
1218
|
+
componentIdRef.current = chunkKRRXA4SI_cjs.uid();
|
|
1147
1219
|
}
|
|
1148
1220
|
const componentId = componentIdRef.current;
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
componentName: displayName,
|
|
1159
|
-
parentId: null
|
|
1160
|
-
};
|
|
1161
|
-
kernel.emit(mountEvent);
|
|
1162
|
-
}
|
|
1163
|
-
return () => {
|
|
1164
|
-
const unmountEvent = {
|
|
1165
|
-
type: "unmount",
|
|
1166
|
-
timestamp: Date.now(),
|
|
1167
|
-
componentId,
|
|
1168
|
-
componentName: displayName
|
|
1169
|
-
};
|
|
1170
|
-
kernel.emit(unmountEvent);
|
|
1171
|
-
};
|
|
1172
|
-
}, [kernel, componentId]);
|
|
1173
|
-
React2.useEffect(() => {
|
|
1174
|
-
if (!kernel || !kernel.isEnabled()) return;
|
|
1175
|
-
const duration = performance.now() - renderStartRef.current;
|
|
1176
|
-
const phase = prevPropsRef.current === null ? "mount" : "update";
|
|
1221
|
+
const renderToken = {};
|
|
1222
|
+
const renderStart = now();
|
|
1223
|
+
useMountTracking(kernel, componentId, displayName, parentId);
|
|
1224
|
+
useIsomorphicLayoutEffect(() => {
|
|
1225
|
+
if (!kernel || !kernel.isEnabled() || committedRenderRef.current === renderToken) return;
|
|
1226
|
+
committedRenderRef.current = renderToken;
|
|
1227
|
+
const currentProps = props;
|
|
1228
|
+
const prevProps = prevPropsRef.current;
|
|
1229
|
+
prevPropsRef.current = { ...currentProps };
|
|
1177
1230
|
const renderEvent = {
|
|
1178
1231
|
type: "render",
|
|
1179
1232
|
timestamp: Date.now(),
|
|
1180
1233
|
componentId,
|
|
1181
1234
|
componentName: displayName,
|
|
1182
|
-
duration,
|
|
1183
|
-
phase
|
|
1235
|
+
duration: now() - renderStart,
|
|
1236
|
+
phase: prevProps === null ? "mount" : "update"
|
|
1184
1237
|
};
|
|
1185
1238
|
kernel.emit(renderEvent);
|
|
1186
|
-
if (
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
next,
|
|
1197
|
-
isDeepEqual: shallowEqual(prev, next)
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
if (changes.length > 0) {
|
|
1239
|
+
if (prevProps !== null) {
|
|
1240
|
+
const changes = diffProps(prevProps, currentProps);
|
|
1241
|
+
if (changes.length === 0) {
|
|
1242
|
+
const detector = kernel.getPlugin("wasted-render-detector");
|
|
1243
|
+
detector?.api.markAsWasted(
|
|
1244
|
+
componentId,
|
|
1245
|
+
"props-unchanged",
|
|
1246
|
+
"Re-rendered with identical props; React.memo would have skipped this render"
|
|
1247
|
+
);
|
|
1248
|
+
} else if (options.trackProps) {
|
|
1202
1249
|
kernel.emit({
|
|
1203
1250
|
type: "props-change",
|
|
1204
1251
|
timestamp: Date.now(),
|
|
@@ -1214,9 +1261,12 @@ function withScope(WrappedComponent, options = {}) {
|
|
|
1214
1261
|
options.onRender(metrics);
|
|
1215
1262
|
}
|
|
1216
1263
|
}
|
|
1217
|
-
prevPropsRef.current = { ...props };
|
|
1218
1264
|
});
|
|
1219
|
-
return
|
|
1265
|
+
return React2__default.default.createElement(
|
|
1266
|
+
ParentScopeContext.Provider,
|
|
1267
|
+
{ value: componentId },
|
|
1268
|
+
React2__default.default.createElement(WrappedComponent, { ...props, ref })
|
|
1269
|
+
);
|
|
1220
1270
|
});
|
|
1221
1271
|
WithScopeComponent.displayName = `withScope(${displayName})`;
|
|
1222
1272
|
return WithScopeComponent;
|
|
@@ -1369,8 +1419,17 @@ function getMetrics() {
|
|
|
1369
1419
|
}
|
|
1370
1420
|
function exportMetrics() {
|
|
1371
1421
|
const kernel = getKernel();
|
|
1372
|
-
const plugin = kernel
|
|
1373
|
-
|
|
1422
|
+
const plugin = kernel.getPlugin("json-exporter");
|
|
1423
|
+
if (plugin) {
|
|
1424
|
+
return plugin.api.exportAll();
|
|
1425
|
+
}
|
|
1426
|
+
const exporter = new chunkEUYOAT56_cjs.JSONExporterPlugin();
|
|
1427
|
+
exporter.install(kernel);
|
|
1428
|
+
try {
|
|
1429
|
+
return exporter.api.exportAll();
|
|
1430
|
+
} finally {
|
|
1431
|
+
exporter.uninstall();
|
|
1432
|
+
}
|
|
1374
1433
|
}
|
|
1375
1434
|
function clearMetrics() {
|
|
1376
1435
|
const kernel = getKernel();
|
|
@@ -1379,11 +1438,11 @@ function clearMetrics() {
|
|
|
1379
1438
|
|
|
1380
1439
|
Object.defineProperty(exports, "TimelineRecorderPlugin", {
|
|
1381
1440
|
enumerable: true,
|
|
1382
|
-
get: function () { return
|
|
1441
|
+
get: function () { return chunkYL2LJ27D_cjs.TimelineRecorderPlugin; }
|
|
1383
1442
|
});
|
|
1384
1443
|
Object.defineProperty(exports, "createTimelineRecorderPlugin", {
|
|
1385
1444
|
enumerable: true,
|
|
1386
|
-
get: function () { return
|
|
1445
|
+
get: function () { return chunkYL2LJ27D_cjs.createTimelineRecorderPlugin; }
|
|
1387
1446
|
});
|
|
1388
1447
|
Object.defineProperty(exports, "MemoryTrackerPlugin", {
|
|
1389
1448
|
enumerable: true,
|
|
@@ -1395,19 +1454,19 @@ Object.defineProperty(exports, "createMemoryTrackerPlugin", {
|
|
|
1395
1454
|
});
|
|
1396
1455
|
Object.defineProperty(exports, "NetworkCorrelatorPlugin", {
|
|
1397
1456
|
enumerable: true,
|
|
1398
|
-
get: function () { return
|
|
1457
|
+
get: function () { return chunkU3TL6KFZ_cjs.NetworkCorrelatorPlugin; }
|
|
1399
1458
|
});
|
|
1400
1459
|
Object.defineProperty(exports, "createNetworkCorrelatorPlugin", {
|
|
1401
1460
|
enumerable: true,
|
|
1402
|
-
get: function () { return
|
|
1461
|
+
get: function () { return chunkU3TL6KFZ_cjs.createNetworkCorrelatorPlugin; }
|
|
1403
1462
|
});
|
|
1404
1463
|
Object.defineProperty(exports, "createIdGenerator", {
|
|
1405
1464
|
enumerable: true,
|
|
1406
|
-
get: function () { return
|
|
1465
|
+
get: function () { return chunkKRRXA4SI_cjs.createIdGenerator; }
|
|
1407
1466
|
});
|
|
1408
1467
|
Object.defineProperty(exports, "uid", {
|
|
1409
1468
|
enumerable: true,
|
|
1410
|
-
get: function () { return
|
|
1469
|
+
get: function () { return chunkKRRXA4SI_cjs.uid; }
|
|
1411
1470
|
});
|
|
1412
1471
|
Object.defineProperty(exports, "RenderTrackerPlugin", {
|
|
1413
1472
|
enumerable: true,
|
|
@@ -1419,43 +1478,43 @@ Object.defineProperty(exports, "createRenderTrackerPlugin", {
|
|
|
1419
1478
|
});
|
|
1420
1479
|
Object.defineProperty(exports, "PropsDifferPlugin", {
|
|
1421
1480
|
enumerable: true,
|
|
1422
|
-
get: function () { return
|
|
1481
|
+
get: function () { return chunkC3IBGU7L_cjs.PropsDifferPlugin; }
|
|
1423
1482
|
});
|
|
1424
1483
|
Object.defineProperty(exports, "createPropsDifferPlugin", {
|
|
1425
1484
|
enumerable: true,
|
|
1426
|
-
get: function () { return
|
|
1485
|
+
get: function () { return chunkC3IBGU7L_cjs.createPropsDifferPlugin; }
|
|
1427
1486
|
});
|
|
1428
1487
|
Object.defineProperty(exports, "deepEqual", {
|
|
1429
1488
|
enumerable: true,
|
|
1430
|
-
get: function () { return
|
|
1489
|
+
get: function () { return chunkC3IBGU7L_cjs.deepEqual; }
|
|
1431
1490
|
});
|
|
1432
1491
|
Object.defineProperty(exports, "WastedRenderDetectorPlugin", {
|
|
1433
1492
|
enumerable: true,
|
|
1434
|
-
get: function () { return
|
|
1493
|
+
get: function () { return chunk7MVKPUC4_cjs.WastedRenderDetectorPlugin; }
|
|
1435
1494
|
});
|
|
1436
1495
|
Object.defineProperty(exports, "createWastedRenderDetectorPlugin", {
|
|
1437
1496
|
enumerable: true,
|
|
1438
|
-
get: function () { return
|
|
1497
|
+
get: function () { return chunk7MVKPUC4_cjs.createWastedRenderDetectorPlugin; }
|
|
1439
1498
|
});
|
|
1440
1499
|
Object.defineProperty(exports, "LifecycleTrackerPlugin", {
|
|
1441
1500
|
enumerable: true,
|
|
1442
|
-
get: function () { return
|
|
1501
|
+
get: function () { return chunk6ALDCO2Q_cjs.LifecycleTrackerPlugin; }
|
|
1443
1502
|
});
|
|
1444
1503
|
Object.defineProperty(exports, "createLifecycleTrackerPlugin", {
|
|
1445
1504
|
enumerable: true,
|
|
1446
|
-
get: function () { return
|
|
1505
|
+
get: function () { return chunk6ALDCO2Q_cjs.createLifecycleTrackerPlugin; }
|
|
1447
1506
|
});
|
|
1448
1507
|
Object.defineProperty(exports, "DashboardUIPlugin", {
|
|
1449
1508
|
enumerable: true,
|
|
1450
|
-
get: function () { return
|
|
1509
|
+
get: function () { return chunk33CBEAOF_cjs.DashboardUIPlugin; }
|
|
1451
1510
|
});
|
|
1452
1511
|
Object.defineProperty(exports, "createDashboardUIPlugin", {
|
|
1453
1512
|
enumerable: true,
|
|
1454
|
-
get: function () { return
|
|
1513
|
+
get: function () { return chunk33CBEAOF_cjs.createDashboardUIPlugin; }
|
|
1455
1514
|
});
|
|
1456
1515
|
Object.defineProperty(exports, "throttle", {
|
|
1457
1516
|
enumerable: true,
|
|
1458
|
-
get: function () { return
|
|
1517
|
+
get: function () { return chunk33CBEAOF_cjs.throttle; }
|
|
1459
1518
|
});
|
|
1460
1519
|
Object.defineProperty(exports, "ConsoleReporterPlugin", {
|
|
1461
1520
|
enumerable: true,
|
|
@@ -1491,11 +1550,11 @@ Object.defineProperty(exports, "formatTimestamp", {
|
|
|
1491
1550
|
});
|
|
1492
1551
|
Object.defineProperty(exports, "JSONExporterPlugin", {
|
|
1493
1552
|
enumerable: true,
|
|
1494
|
-
get: function () { return
|
|
1553
|
+
get: function () { return chunkEUYOAT56_cjs.JSONExporterPlugin; }
|
|
1495
1554
|
});
|
|
1496
1555
|
Object.defineProperty(exports, "createJSONExporterPlugin", {
|
|
1497
1556
|
enumerable: true,
|
|
1498
|
-
get: function () { return
|
|
1557
|
+
get: function () { return chunkEUYOAT56_cjs.createJSONExporterPlugin; }
|
|
1499
1558
|
});
|
|
1500
1559
|
exports.ReactScopeProvider = ReactScopeProvider;
|
|
1501
1560
|
exports.Scope = Scope;
|