@oxog/react-check 1.1.2 → 1.1.5
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 +22 -0
- package/dist/browser-inject.global.js +8 -8
- package/dist/cli.js +49 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +39 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +39 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1180,14 +1180,23 @@ declare class Overlay {
|
|
|
1180
1180
|
* @packageDocumentation
|
|
1181
1181
|
*/
|
|
1182
1182
|
|
|
1183
|
+
/**
|
|
1184
|
+
* Render event with DOM element reference
|
|
1185
|
+
*/
|
|
1186
|
+
interface RenderEvent {
|
|
1187
|
+
/** Render information */
|
|
1188
|
+
render: RenderInfo;
|
|
1189
|
+
/** DOM element associated with this render (if found) */
|
|
1190
|
+
element: Element | null;
|
|
1191
|
+
}
|
|
1183
1192
|
/**
|
|
1184
1193
|
* Browser scanner events
|
|
1185
1194
|
*/
|
|
1186
1195
|
interface BrowserScannerEvents {
|
|
1187
1196
|
/** Index signature for EventMap compatibility */
|
|
1188
1197
|
[key: string]: unknown;
|
|
1189
|
-
/** Emitted on each render */
|
|
1190
|
-
render:
|
|
1198
|
+
/** Emitted on each render with DOM element */
|
|
1199
|
+
render: RenderEvent;
|
|
1191
1200
|
/** Emitted when scanner is ready */
|
|
1192
1201
|
ready: {
|
|
1193
1202
|
reactVersion: string;
|
|
@@ -1273,10 +1282,10 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
|
|
|
1273
1282
|
*/
|
|
1274
1283
|
private detectReactVersion;
|
|
1275
1284
|
/**
|
|
1276
|
-
* Process a fiber commit
|
|
1285
|
+
* Process a fiber commit (public for IIFE hook integration)
|
|
1277
1286
|
* @param rootFiber - Root fiber of the committed tree
|
|
1278
1287
|
*/
|
|
1279
|
-
|
|
1288
|
+
processCommit(rootFiber: FiberNode): void;
|
|
1280
1289
|
/**
|
|
1281
1290
|
* Walk the fiber tree
|
|
1282
1291
|
* @param fiber - Current fiber
|
|
@@ -1412,12 +1421,6 @@ declare class ReactCheckInjector {
|
|
|
1412
1421
|
* Flush queued messages after connection
|
|
1413
1422
|
*/
|
|
1414
1423
|
private flushMessageQueue;
|
|
1415
|
-
/**
|
|
1416
|
-
* Find DOM element for a component
|
|
1417
|
-
* @param componentName - Component name
|
|
1418
|
-
* @returns DOM element or null
|
|
1419
|
-
*/
|
|
1420
|
-
private findDOMElement;
|
|
1421
1424
|
/**
|
|
1422
1425
|
* Destroy the injector
|
|
1423
1426
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1180,14 +1180,23 @@ declare class Overlay {
|
|
|
1180
1180
|
* @packageDocumentation
|
|
1181
1181
|
*/
|
|
1182
1182
|
|
|
1183
|
+
/**
|
|
1184
|
+
* Render event with DOM element reference
|
|
1185
|
+
*/
|
|
1186
|
+
interface RenderEvent {
|
|
1187
|
+
/** Render information */
|
|
1188
|
+
render: RenderInfo;
|
|
1189
|
+
/** DOM element associated with this render (if found) */
|
|
1190
|
+
element: Element | null;
|
|
1191
|
+
}
|
|
1183
1192
|
/**
|
|
1184
1193
|
* Browser scanner events
|
|
1185
1194
|
*/
|
|
1186
1195
|
interface BrowserScannerEvents {
|
|
1187
1196
|
/** Index signature for EventMap compatibility */
|
|
1188
1197
|
[key: string]: unknown;
|
|
1189
|
-
/** Emitted on each render */
|
|
1190
|
-
render:
|
|
1198
|
+
/** Emitted on each render with DOM element */
|
|
1199
|
+
render: RenderEvent;
|
|
1191
1200
|
/** Emitted when scanner is ready */
|
|
1192
1201
|
ready: {
|
|
1193
1202
|
reactVersion: string;
|
|
@@ -1273,10 +1282,10 @@ declare class BrowserScanner extends EventEmitter<BrowserScannerEvents> {
|
|
|
1273
1282
|
*/
|
|
1274
1283
|
private detectReactVersion;
|
|
1275
1284
|
/**
|
|
1276
|
-
* Process a fiber commit
|
|
1285
|
+
* Process a fiber commit (public for IIFE hook integration)
|
|
1277
1286
|
* @param rootFiber - Root fiber of the committed tree
|
|
1278
1287
|
*/
|
|
1279
|
-
|
|
1288
|
+
processCommit(rootFiber: FiberNode): void;
|
|
1280
1289
|
/**
|
|
1281
1290
|
* Walk the fiber tree
|
|
1282
1291
|
* @param fiber - Current fiber
|
|
@@ -1412,12 +1421,6 @@ declare class ReactCheckInjector {
|
|
|
1412
1421
|
* Flush queued messages after connection
|
|
1413
1422
|
*/
|
|
1414
1423
|
private flushMessageQueue;
|
|
1415
|
-
/**
|
|
1416
|
-
* Find DOM element for a component
|
|
1417
|
-
* @param componentName - Component name
|
|
1418
|
-
* @returns DOM element or null
|
|
1419
|
-
*/
|
|
1420
|
-
private findDOMElement;
|
|
1421
1424
|
/**
|
|
1422
1425
|
* Destroy the injector
|
|
1423
1426
|
*/
|
package/dist/index.js
CHANGED
|
@@ -760,7 +760,6 @@ var init_browser = __esm({
|
|
|
760
760
|
const wsPort = this.options.wsPort;
|
|
761
761
|
await this.page.evaluateOnNewDocument(`
|
|
762
762
|
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
763
|
-
window.__REACTCHECK_INJECTED__ = true;
|
|
764
763
|
`);
|
|
765
764
|
this.emit("launched", void 0);
|
|
766
765
|
logger3.info("Browser launched");
|
|
@@ -5360,7 +5359,7 @@ var BrowserScanner = class extends EventEmitter {
|
|
|
5360
5359
|
return "unknown";
|
|
5361
5360
|
}
|
|
5362
5361
|
/**
|
|
5363
|
-
* Process a fiber commit
|
|
5362
|
+
* Process a fiber commit (public for IIFE hook integration)
|
|
5364
5363
|
* @param rootFiber - Root fiber of the committed tree
|
|
5365
5364
|
*/
|
|
5366
5365
|
processCommit(rootFiber) {
|
|
@@ -5406,15 +5405,15 @@ var BrowserScanner = class extends EventEmitter {
|
|
|
5406
5405
|
props: fiber.memoizedProps,
|
|
5407
5406
|
state: fiber.memoizedState
|
|
5408
5407
|
});
|
|
5408
|
+
const domElement = this.getDOMElement(fiber);
|
|
5409
5409
|
if (this.overlay && this.config.highlightRenders) {
|
|
5410
|
-
const domElement = this.getDOMElement(fiber);
|
|
5411
5410
|
if (domElement) {
|
|
5412
5411
|
this.overlay.highlight(renderInfo, domElement);
|
|
5413
5412
|
} else {
|
|
5414
5413
|
this.overlay.recordRender(renderInfo);
|
|
5415
5414
|
}
|
|
5416
5415
|
}
|
|
5417
|
-
this.emit("render", renderInfo);
|
|
5416
|
+
this.emit("render", { render: renderInfo, element: domElement });
|
|
5418
5417
|
}
|
|
5419
5418
|
/**
|
|
5420
5419
|
* Check if component should be filtered out
|
|
@@ -5537,7 +5536,6 @@ var ReactCheckInjector = class {
|
|
|
5537
5536
|
this.initialized = true;
|
|
5538
5537
|
this.overlay.init();
|
|
5539
5538
|
this.setupScannerEvents();
|
|
5540
|
-
this.scanner.start();
|
|
5541
5539
|
this.connect();
|
|
5542
5540
|
const markHookReady = this._markHookReady;
|
|
5543
5541
|
if (markHookReady) {
|
|
@@ -5549,10 +5547,9 @@ var ReactCheckInjector = class {
|
|
|
5549
5547
|
* Set up scanner event handlers
|
|
5550
5548
|
*/
|
|
5551
5549
|
setupScannerEvents() {
|
|
5552
|
-
this.scanner.on("render", (render) => {
|
|
5550
|
+
this.scanner.on("render", ({ render, element }) => {
|
|
5553
5551
|
this.send({ type: "render", payload: render });
|
|
5554
5552
|
this.overlay.recordRender(render);
|
|
5555
|
-
const element = this.findDOMElement(render.componentName);
|
|
5556
5553
|
if (element) {
|
|
5557
5554
|
this.overlay.highlight(render, element);
|
|
5558
5555
|
}
|
|
@@ -5587,7 +5584,6 @@ var ReactCheckInjector = class {
|
|
|
5587
5584
|
payload: { reactVersion: this.scanner.getReactVersion() }
|
|
5588
5585
|
});
|
|
5589
5586
|
this.flushMessageQueue();
|
|
5590
|
-
this.scanner.start();
|
|
5591
5587
|
};
|
|
5592
5588
|
this.ws.onmessage = (event) => {
|
|
5593
5589
|
try {
|
|
@@ -5713,18 +5709,6 @@ var ReactCheckInjector = class {
|
|
|
5713
5709
|
this.messageQueue = [];
|
|
5714
5710
|
}
|
|
5715
5711
|
}
|
|
5716
|
-
/**
|
|
5717
|
-
* Find DOM element for a component
|
|
5718
|
-
* @param componentName - Component name
|
|
5719
|
-
* @returns DOM element or null
|
|
5720
|
-
*/
|
|
5721
|
-
findDOMElement(componentName) {
|
|
5722
|
-
const byAttr = document.querySelector(`[data-component="${componentName}"]`);
|
|
5723
|
-
if (byAttr) return byAttr;
|
|
5724
|
-
const allElements = document.querySelectorAll('[class*="' + componentName + '"]');
|
|
5725
|
-
if (allElements.length > 0) return allElements[0] ?? null;
|
|
5726
|
-
return null;
|
|
5727
|
-
}
|
|
5728
5712
|
/**
|
|
5729
5713
|
* Destroy the injector
|
|
5730
5714
|
*/
|
|
@@ -5747,9 +5731,30 @@ var ReactCheckInjector = class {
|
|
|
5747
5731
|
}
|
|
5748
5732
|
win.__REACTCHECK_INJECTED__ = true;
|
|
5749
5733
|
const injector = new ReactCheckInjector();
|
|
5734
|
+
const pendingCommits = [];
|
|
5735
|
+
let injectorReady = false;
|
|
5736
|
+
const handleCommit = (root) => {
|
|
5737
|
+
if (injectorReady) {
|
|
5738
|
+
const scanner = injector.scanner;
|
|
5739
|
+
if (scanner) {
|
|
5740
|
+
const fiber = root.current;
|
|
5741
|
+
scanner.processCommit(fiber);
|
|
5742
|
+
}
|
|
5743
|
+
} else {
|
|
5744
|
+
pendingCommits.push({ rendererID: 0, root });
|
|
5745
|
+
}
|
|
5746
|
+
};
|
|
5747
|
+
const processPendingCommits = () => {
|
|
5748
|
+
injectorReady = true;
|
|
5749
|
+
const scanner = injector.scanner;
|
|
5750
|
+
if (scanner) {
|
|
5751
|
+
for (const { root } of pendingCommits) {
|
|
5752
|
+
scanner.processCommit(root.current);
|
|
5753
|
+
}
|
|
5754
|
+
pendingCommits.length = 0;
|
|
5755
|
+
}
|
|
5756
|
+
};
|
|
5750
5757
|
if (!win.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
5751
|
-
const pendingCommits = [];
|
|
5752
|
-
let injectorReady = false;
|
|
5753
5758
|
const hook = {
|
|
5754
5759
|
renderers: /* @__PURE__ */ new Map(),
|
|
5755
5760
|
supportsFiber: true,
|
|
@@ -5758,36 +5763,26 @@ var ReactCheckInjector = class {
|
|
|
5758
5763
|
this.renderers.set(id, renderer);
|
|
5759
5764
|
return id;
|
|
5760
5765
|
},
|
|
5761
|
-
onCommitFiberRoot: function(
|
|
5762
|
-
|
|
5763
|
-
const scanner = injector.scanner;
|
|
5764
|
-
if (scanner) {
|
|
5765
|
-
scanner["processCommit"](root.current);
|
|
5766
|
-
}
|
|
5767
|
-
} else {
|
|
5768
|
-
pendingCommits.push({ rendererID, root });
|
|
5769
|
-
}
|
|
5766
|
+
onCommitFiberRoot: function(_rendererID, root) {
|
|
5767
|
+
handleCommit(root);
|
|
5770
5768
|
},
|
|
5771
5769
|
onCommitFiberUnmount: function() {
|
|
5772
|
-
},
|
|
5773
|
-
// Method to process pending commits when injector is ready
|
|
5774
|
-
_processPending: function() {
|
|
5775
|
-
injectorReady = true;
|
|
5776
|
-
const scanner = injector.scanner;
|
|
5777
|
-
if (scanner) {
|
|
5778
|
-
for (const { root } of pendingCommits) {
|
|
5779
|
-
scanner["processCommit"](root.current);
|
|
5780
|
-
}
|
|
5781
|
-
pendingCommits.length = 0;
|
|
5782
|
-
}
|
|
5783
5770
|
}
|
|
5784
5771
|
};
|
|
5785
5772
|
win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
5786
5773
|
console.log("[ReactCheck] DevTools hook installed");
|
|
5787
|
-
|
|
5788
|
-
|
|
5774
|
+
} else {
|
|
5775
|
+
const existingHook = win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
5776
|
+
const originalOnCommit = existingHook.onCommitFiberRoot.bind(existingHook);
|
|
5777
|
+
existingHook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
|
|
5778
|
+
originalOnCommit(rendererID, root, priorityLevel);
|
|
5779
|
+
handleCommit(root);
|
|
5789
5780
|
};
|
|
5781
|
+
console.log("[ReactCheck] Wrapped existing DevTools hook");
|
|
5790
5782
|
}
|
|
5783
|
+
injector._markHookReady = () => {
|
|
5784
|
+
processPendingCommits();
|
|
5785
|
+
};
|
|
5791
5786
|
if (document.readyState === "loading") {
|
|
5792
5787
|
document.addEventListener("DOMContentLoaded", () => {
|
|
5793
5788
|
injector.init();
|