@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/dist/index.cjs CHANGED
@@ -5210,6 +5210,18 @@ var Overlay = class {
5210
5210
  if (render.renderCount > 20) return "warning";
5211
5211
  return "healthy";
5212
5212
  }
5213
+ /**
5214
+ * Record a render event (updates stats even without DOM element)
5215
+ * @param render - Render information
5216
+ */
5217
+ recordRender(render) {
5218
+ const count = (this.renderCounts.get(render.componentName) ?? 0) + 1;
5219
+ this.renderCounts.set(render.componentName, count);
5220
+ this.totalRenders++;
5221
+ this.updateStats();
5222
+ }
5223
+ /** Total render count */
5224
+ totalRenders = 0;
5213
5225
  /**
5214
5226
  * Update toolbar stats
5215
5227
  */
@@ -5218,9 +5230,7 @@ var Overlay = class {
5218
5230
  let critical = 0;
5219
5231
  let warning = 0;
5220
5232
  let healthy = 0;
5221
- let total = 0;
5222
5233
  for (const [, count] of this.renderCounts) {
5223
- total += count;
5224
5234
  if (count > 50) critical++;
5225
5235
  else if (count > 20) warning++;
5226
5236
  else healthy++;
@@ -5232,7 +5242,7 @@ var Overlay = class {
5232
5242
  if (criticalEl) criticalEl.textContent = String(critical);
5233
5243
  if (warningEl) warningEl.textContent = String(warning);
5234
5244
  if (healthyEl) healthyEl.textContent = String(healthy);
5235
- if (rendersEl) rendersEl.textContent = String(total);
5245
+ if (rendersEl) rendersEl.textContent = String(this.totalRenders);
5236
5246
  }
5237
5247
  /**
5238
5248
  * Clear all highlights
@@ -5259,6 +5269,7 @@ var Overlay = class {
5259
5269
  this.clearHighlights();
5260
5270
  this.clearBadges();
5261
5271
  this.renderCounts.clear();
5272
+ this.totalRenders = 0;
5262
5273
  this.updateStats();
5263
5274
  }
5264
5275
  /**
@@ -5345,7 +5356,12 @@ var ReactCheckInjector = class {
5345
5356
  this.initialized = true;
5346
5357
  this.overlay.init();
5347
5358
  this.setupScannerEvents();
5359
+ this.scanner.start();
5348
5360
  this.connect();
5361
+ const markHookReady = this._markHookReady;
5362
+ if (markHookReady) {
5363
+ markHookReady();
5364
+ }
5349
5365
  console.log("[ReactCheck] Initialized");
5350
5366
  }
5351
5367
  /**
@@ -5354,6 +5370,7 @@ var ReactCheckInjector = class {
5354
5370
  setupScannerEvents() {
5355
5371
  this.scanner.on("render", (render) => {
5356
5372
  this.send({ type: "render", payload: render });
5373
+ this.overlay.recordRender(render);
5357
5374
  const element = this.findDOMElement(render.componentName);
5358
5375
  if (element) {
5359
5376
  this.overlay.highlight(render, element);
@@ -5388,6 +5405,7 @@ var ReactCheckInjector = class {
5388
5405
  type: "ready",
5389
5406
  payload: { reactVersion: this.scanner.getReactVersion() }
5390
5407
  });
5408
+ this.flushMessageQueue();
5391
5409
  this.scanner.start();
5392
5410
  };
5393
5411
  this.ws.onmessage = (event) => {
@@ -5456,6 +5474,8 @@ var ReactCheckInjector = class {
5456
5474
  this.overlay.configure({ animationSpeed: config.animationSpeed });
5457
5475
  }
5458
5476
  }
5477
+ /** Message queue for messages sent before connection */
5478
+ messageQueue = [];
5459
5479
  /**
5460
5480
  * Send message to CLI
5461
5481
  * @param message - Browser message
@@ -5463,6 +5483,19 @@ var ReactCheckInjector = class {
5463
5483
  send(message) {
5464
5484
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
5465
5485
  this.ws.send(JSON.stringify(message));
5486
+ } else {
5487
+ this.messageQueue.push(message);
5488
+ }
5489
+ }
5490
+ /**
5491
+ * Flush queued messages after connection
5492
+ */
5493
+ flushMessageQueue() {
5494
+ if (this.ws && this.ws.readyState === WebSocket.OPEN && this.messageQueue.length > 0) {
5495
+ for (const message of this.messageQueue) {
5496
+ this.ws.send(JSON.stringify(message));
5497
+ }
5498
+ this.messageQueue = [];
5466
5499
  }
5467
5500
  }
5468
5501
  /**
@@ -5498,7 +5531,10 @@ var ReactCheckInjector = class {
5498
5531
  return;
5499
5532
  }
5500
5533
  win.__REACTCHECK_INJECTED__ = true;
5534
+ const injector = new ReactCheckInjector();
5501
5535
  if (!win.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
5536
+ const pendingCommits = [];
5537
+ let injectorReady = false;
5502
5538
  const hook = {
5503
5539
  renderers: /* @__PURE__ */ new Map(),
5504
5540
  supportsFiber: true,
@@ -5507,15 +5543,36 @@ var ReactCheckInjector = class {
5507
5543
  this.renderers.set(id, renderer);
5508
5544
  return id;
5509
5545
  },
5510
- onCommitFiberRoot: function() {
5546
+ onCommitFiberRoot: function(rendererID, root) {
5547
+ if (injectorReady) {
5548
+ const scanner = injector.scanner;
5549
+ if (scanner) {
5550
+ scanner["processCommit"](root.current);
5551
+ }
5552
+ } else {
5553
+ pendingCommits.push({ rendererID, root });
5554
+ }
5511
5555
  },
5512
5556
  onCommitFiberUnmount: function() {
5557
+ },
5558
+ // Method to process pending commits when injector is ready
5559
+ _processPending: function() {
5560
+ injectorReady = true;
5561
+ const scanner = injector.scanner;
5562
+ if (scanner) {
5563
+ for (const { root } of pendingCommits) {
5564
+ scanner["processCommit"](root.current);
5565
+ }
5566
+ pendingCommits.length = 0;
5567
+ }
5513
5568
  }
5514
5569
  };
5515
5570
  win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
5516
5571
  console.log("[ReactCheck] DevTools hook installed");
5572
+ injector._markHookReady = () => {
5573
+ hook._processPending();
5574
+ };
5517
5575
  }
5518
- const injector = new ReactCheckInjector();
5519
5576
  if (document.readyState === "loading") {
5520
5577
  document.addEventListener("DOMContentLoaded", () => {
5521
5578
  injector.init();