Skip to content

Commit 1da28d3

Browse files
committed
push
1 parent 8483e38 commit 1da28d3

File tree

12 files changed

+479
-343
lines changed

12 files changed

+479
-343
lines changed

packages/scan/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-scan",
3-
"version": "0.0.44",
3+
"version": "0.0.45",
44
"description": "Scan your React app for renders",
55
"keywords": [
66
"react",
@@ -92,6 +92,11 @@
9292
}
9393
}
9494
},
95+
"./install-hook": {
96+
"types": "./dist/install-hook.d.ts",
97+
"import": "./dist/install-hook.mjs",
98+
"require": "./dist/install-hook.js"
99+
},
95100
"./auto": {
96101
"production": {
97102
"import": {
@@ -235,7 +240,7 @@
235240
"@preact/signals": "^1.3.1",
236241
"@rollup/pluginutils": "^5.1.3",
237242
"@types/node": "^20.17.9",
238-
"bippy": "^0.0.14",
243+
"bippy": "^0.0.18",
239244
"esbuild": "^0.24.0",
240245
"estree-walker": "^3.0.3",
241246
"kleur": "^4.1.5",
@@ -254,6 +259,7 @@
254259
"@typescript-eslint/eslint-plugin": "^6.0.0",
255260
"@typescript-eslint/parser": "^6.0.0",
256261
"@vercel/style-guide": "^6.0.0",
262+
"es-module-lexer": "^1.5.4",
257263
"eslint": "^8.0.0",
258264
"next": "*",
259265
"prettier": "^3.3.3",

packages/scan/src/auto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'bippy';
1+
import 'bippy'; // implicit init RDT hook
22
import { scan } from './index';
33

44
if (typeof window !== 'undefined') {

packages/scan/src/core/index.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { Fiber } from 'react-reconciler';
22
import type * as React from 'react';
33
import { type Signal, signal } from '@preact/signals';
4-
import { getDisplayName, getTimings, getType, isCompositeFiber } from 'bippy';
4+
import {
5+
getDisplayName,
6+
getTimings,
7+
getType,
8+
isCompositeFiber,
9+
traverseFiber,
10+
} from 'bippy';
511
import { createInstrumentation, type Render } from './instrumentation';
612
import {
713
type ActiveOutline,
@@ -18,11 +24,7 @@ import {
1824
import { createToolbar } from './web/toolbar';
1925
import type { InternalInteraction } from './monitor/types';
2026
import { type getSession } from './monitor/utils';
21-
import {
22-
isValidFiber,
23-
type RenderData,
24-
updateFiberRenderData,
25-
} from './utils';
27+
import { type RenderData, updateFiberRenderData } from './utils';
2628
import { playGeigerClickSound } from './web/geiger';
2729

2830
export interface Options {
@@ -275,6 +277,30 @@ export const reportRender = (fiber: Fiber, renders: Array<Render>) => {
275277
}
276278
};
277279

280+
export const isValidFiber = (fiber: Fiber) => {
281+
if (ignoredProps.has(fiber.memoizedProps)) {
282+
return false;
283+
}
284+
285+
const allowList = ReactScanInternals.componentAllowList;
286+
const shouldAllow =
287+
allowList?.has(fiber.type) ?? allowList?.has(fiber.elementType);
288+
289+
if (shouldAllow) {
290+
const parent = traverseFiber(
291+
fiber,
292+
(node) => {
293+
const options =
294+
allowList?.get(node.type) ?? allowList?.get(node.elementType);
295+
return options?.includeChildren;
296+
},
297+
true,
298+
);
299+
if (!parent && !shouldAllow) return false;
300+
}
301+
return true;
302+
};
303+
278304
export const start = () => {
279305
if (typeof window === 'undefined') return;
280306
const options = ReactScanInternals.options.value;
@@ -304,14 +330,15 @@ export const start = () => {
304330
};
305331

306332
// TODO: dynamic enable, and inspect-off check
307-
const instrumentation = createInstrumentation({
308-
kind: 'devtool',
333+
const instrumentation = createInstrumentation('devtools', {
309334
onCommitStart() {
310335
ReactScanInternals.options.value.onCommitStart?.();
311336
},
312-
isValidFiber(fiber) {
313-
return isValidFiber(fiber);
337+
onError(error) {
338+
// eslint-disable-next-line no-console
339+
console.error('[React Scan] Error instrumenting:', error);
314340
},
341+
isValidFiber,
315342
onRender(fiber, renders) {
316343
if (ReactScanInternals.instrumentation?.isPaused.value) {
317344
// don't draw if it's paused

0 commit comments

Comments
 (0)