@oxog/react-check 1.0.2 → 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/CHANGELOG.md +58 -0
- package/README.md +54 -0
- package/dist/browser-inject.global.js +2 -2
- package/dist/cli.js +2207 -179
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +62 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +62 -5
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
package/dist/index.d.cts
CHANGED
|
@@ -1257,6 +1257,13 @@ declare class Overlay {
|
|
|
1257
1257
|
* @returns Severity level
|
|
1258
1258
|
*/
|
|
1259
1259
|
private getSeverity;
|
|
1260
|
+
/**
|
|
1261
|
+
* Record a render event (updates stats even without DOM element)
|
|
1262
|
+
* @param render - Render information
|
|
1263
|
+
*/
|
|
1264
|
+
recordRender(render: RenderInfo): void;
|
|
1265
|
+
/** Total render count */
|
|
1266
|
+
private totalRenders;
|
|
1260
1267
|
/**
|
|
1261
1268
|
* Update toolbar stats
|
|
1262
1269
|
*/
|
|
@@ -1349,11 +1356,17 @@ declare class ReactCheckInjector {
|
|
|
1349
1356
|
* @param config - New configuration
|
|
1350
1357
|
*/
|
|
1351
1358
|
private handleConfig;
|
|
1359
|
+
/** Message queue for messages sent before connection */
|
|
1360
|
+
private messageQueue;
|
|
1352
1361
|
/**
|
|
1353
1362
|
* Send message to CLI
|
|
1354
1363
|
* @param message - Browser message
|
|
1355
1364
|
*/
|
|
1356
1365
|
private send;
|
|
1366
|
+
/**
|
|
1367
|
+
* Flush queued messages after connection
|
|
1368
|
+
*/
|
|
1369
|
+
private flushMessageQueue;
|
|
1357
1370
|
/**
|
|
1358
1371
|
* Find DOM element for a component
|
|
1359
1372
|
* @param componentName - Component name
|
package/dist/index.d.ts
CHANGED
|
@@ -1257,6 +1257,13 @@ declare class Overlay {
|
|
|
1257
1257
|
* @returns Severity level
|
|
1258
1258
|
*/
|
|
1259
1259
|
private getSeverity;
|
|
1260
|
+
/**
|
|
1261
|
+
* Record a render event (updates stats even without DOM element)
|
|
1262
|
+
* @param render - Render information
|
|
1263
|
+
*/
|
|
1264
|
+
recordRender(render: RenderInfo): void;
|
|
1265
|
+
/** Total render count */
|
|
1266
|
+
private totalRenders;
|
|
1260
1267
|
/**
|
|
1261
1268
|
* Update toolbar stats
|
|
1262
1269
|
*/
|
|
@@ -1349,11 +1356,17 @@ declare class ReactCheckInjector {
|
|
|
1349
1356
|
* @param config - New configuration
|
|
1350
1357
|
*/
|
|
1351
1358
|
private handleConfig;
|
|
1359
|
+
/** Message queue for messages sent before connection */
|
|
1360
|
+
private messageQueue;
|
|
1352
1361
|
/**
|
|
1353
1362
|
* Send message to CLI
|
|
1354
1363
|
* @param message - Browser message
|
|
1355
1364
|
*/
|
|
1356
1365
|
private send;
|
|
1366
|
+
/**
|
|
1367
|
+
* Flush queued messages after connection
|
|
1368
|
+
*/
|
|
1369
|
+
private flushMessageQueue;
|
|
1357
1370
|
/**
|
|
1358
1371
|
* Find DOM element for a component
|
|
1359
1372
|
* @param componentName - Component name
|
package/dist/index.js
CHANGED
|
@@ -5208,6 +5208,18 @@ var Overlay = class {
|
|
|
5208
5208
|
if (render.renderCount > 20) return "warning";
|
|
5209
5209
|
return "healthy";
|
|
5210
5210
|
}
|
|
5211
|
+
/**
|
|
5212
|
+
* Record a render event (updates stats even without DOM element)
|
|
5213
|
+
* @param render - Render information
|
|
5214
|
+
*/
|
|
5215
|
+
recordRender(render) {
|
|
5216
|
+
const count = (this.renderCounts.get(render.componentName) ?? 0) + 1;
|
|
5217
|
+
this.renderCounts.set(render.componentName, count);
|
|
5218
|
+
this.totalRenders++;
|
|
5219
|
+
this.updateStats();
|
|
5220
|
+
}
|
|
5221
|
+
/** Total render count */
|
|
5222
|
+
totalRenders = 0;
|
|
5211
5223
|
/**
|
|
5212
5224
|
* Update toolbar stats
|
|
5213
5225
|
*/
|
|
@@ -5216,9 +5228,7 @@ var Overlay = class {
|
|
|
5216
5228
|
let critical = 0;
|
|
5217
5229
|
let warning = 0;
|
|
5218
5230
|
let healthy = 0;
|
|
5219
|
-
let total = 0;
|
|
5220
5231
|
for (const [, count] of this.renderCounts) {
|
|
5221
|
-
total += count;
|
|
5222
5232
|
if (count > 50) critical++;
|
|
5223
5233
|
else if (count > 20) warning++;
|
|
5224
5234
|
else healthy++;
|
|
@@ -5230,7 +5240,7 @@ var Overlay = class {
|
|
|
5230
5240
|
if (criticalEl) criticalEl.textContent = String(critical);
|
|
5231
5241
|
if (warningEl) warningEl.textContent = String(warning);
|
|
5232
5242
|
if (healthyEl) healthyEl.textContent = String(healthy);
|
|
5233
|
-
if (rendersEl) rendersEl.textContent = String(
|
|
5243
|
+
if (rendersEl) rendersEl.textContent = String(this.totalRenders);
|
|
5234
5244
|
}
|
|
5235
5245
|
/**
|
|
5236
5246
|
* Clear all highlights
|
|
@@ -5257,6 +5267,7 @@ var Overlay = class {
|
|
|
5257
5267
|
this.clearHighlights();
|
|
5258
5268
|
this.clearBadges();
|
|
5259
5269
|
this.renderCounts.clear();
|
|
5270
|
+
this.totalRenders = 0;
|
|
5260
5271
|
this.updateStats();
|
|
5261
5272
|
}
|
|
5262
5273
|
/**
|
|
@@ -5343,7 +5354,12 @@ var ReactCheckInjector = class {
|
|
|
5343
5354
|
this.initialized = true;
|
|
5344
5355
|
this.overlay.init();
|
|
5345
5356
|
this.setupScannerEvents();
|
|
5357
|
+
this.scanner.start();
|
|
5346
5358
|
this.connect();
|
|
5359
|
+
const markHookReady = this._markHookReady;
|
|
5360
|
+
if (markHookReady) {
|
|
5361
|
+
markHookReady();
|
|
5362
|
+
}
|
|
5347
5363
|
console.log("[ReactCheck] Initialized");
|
|
5348
5364
|
}
|
|
5349
5365
|
/**
|
|
@@ -5352,6 +5368,7 @@ var ReactCheckInjector = class {
|
|
|
5352
5368
|
setupScannerEvents() {
|
|
5353
5369
|
this.scanner.on("render", (render) => {
|
|
5354
5370
|
this.send({ type: "render", payload: render });
|
|
5371
|
+
this.overlay.recordRender(render);
|
|
5355
5372
|
const element = this.findDOMElement(render.componentName);
|
|
5356
5373
|
if (element) {
|
|
5357
5374
|
this.overlay.highlight(render, element);
|
|
@@ -5386,6 +5403,7 @@ var ReactCheckInjector = class {
|
|
|
5386
5403
|
type: "ready",
|
|
5387
5404
|
payload: { reactVersion: this.scanner.getReactVersion() }
|
|
5388
5405
|
});
|
|
5406
|
+
this.flushMessageQueue();
|
|
5389
5407
|
this.scanner.start();
|
|
5390
5408
|
};
|
|
5391
5409
|
this.ws.onmessage = (event) => {
|
|
@@ -5454,6 +5472,8 @@ var ReactCheckInjector = class {
|
|
|
5454
5472
|
this.overlay.configure({ animationSpeed: config.animationSpeed });
|
|
5455
5473
|
}
|
|
5456
5474
|
}
|
|
5475
|
+
/** Message queue for messages sent before connection */
|
|
5476
|
+
messageQueue = [];
|
|
5457
5477
|
/**
|
|
5458
5478
|
* Send message to CLI
|
|
5459
5479
|
* @param message - Browser message
|
|
@@ -5461,6 +5481,19 @@ var ReactCheckInjector = class {
|
|
|
5461
5481
|
send(message) {
|
|
5462
5482
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
5463
5483
|
this.ws.send(JSON.stringify(message));
|
|
5484
|
+
} else {
|
|
5485
|
+
this.messageQueue.push(message);
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
/**
|
|
5489
|
+
* Flush queued messages after connection
|
|
5490
|
+
*/
|
|
5491
|
+
flushMessageQueue() {
|
|
5492
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN && this.messageQueue.length > 0) {
|
|
5493
|
+
for (const message of this.messageQueue) {
|
|
5494
|
+
this.ws.send(JSON.stringify(message));
|
|
5495
|
+
}
|
|
5496
|
+
this.messageQueue = [];
|
|
5464
5497
|
}
|
|
5465
5498
|
}
|
|
5466
5499
|
/**
|
|
@@ -5496,7 +5529,10 @@ var ReactCheckInjector = class {
|
|
|
5496
5529
|
return;
|
|
5497
5530
|
}
|
|
5498
5531
|
win.__REACTCHECK_INJECTED__ = true;
|
|
5532
|
+
const injector = new ReactCheckInjector();
|
|
5499
5533
|
if (!win.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
5534
|
+
const pendingCommits = [];
|
|
5535
|
+
let injectorReady = false;
|
|
5500
5536
|
const hook = {
|
|
5501
5537
|
renderers: /* @__PURE__ */ new Map(),
|
|
5502
5538
|
supportsFiber: true,
|
|
@@ -5505,15 +5541,36 @@ var ReactCheckInjector = class {
|
|
|
5505
5541
|
this.renderers.set(id, renderer);
|
|
5506
5542
|
return id;
|
|
5507
5543
|
},
|
|
5508
|
-
onCommitFiberRoot: function() {
|
|
5544
|
+
onCommitFiberRoot: function(rendererID, root) {
|
|
5545
|
+
if (injectorReady) {
|
|
5546
|
+
const scanner = injector.scanner;
|
|
5547
|
+
if (scanner) {
|
|
5548
|
+
scanner["processCommit"](root.current);
|
|
5549
|
+
}
|
|
5550
|
+
} else {
|
|
5551
|
+
pendingCommits.push({ rendererID, root });
|
|
5552
|
+
}
|
|
5509
5553
|
},
|
|
5510
5554
|
onCommitFiberUnmount: function() {
|
|
5555
|
+
},
|
|
5556
|
+
// Method to process pending commits when injector is ready
|
|
5557
|
+
_processPending: function() {
|
|
5558
|
+
injectorReady = true;
|
|
5559
|
+
const scanner = injector.scanner;
|
|
5560
|
+
if (scanner) {
|
|
5561
|
+
for (const { root } of pendingCommits) {
|
|
5562
|
+
scanner["processCommit"](root.current);
|
|
5563
|
+
}
|
|
5564
|
+
pendingCommits.length = 0;
|
|
5565
|
+
}
|
|
5511
5566
|
}
|
|
5512
5567
|
};
|
|
5513
5568
|
win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
5514
5569
|
console.log("[ReactCheck] DevTools hook installed");
|
|
5570
|
+
injector._markHookReady = () => {
|
|
5571
|
+
hook._processPending();
|
|
5572
|
+
};
|
|
5515
5573
|
}
|
|
5516
|
-
const injector = new ReactCheckInjector();
|
|
5517
5574
|
if (document.readyState === "loading") {
|
|
5518
5575
|
document.addEventListener("DOMContentLoaded", () => {
|
|
5519
5576
|
injector.init();
|