Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Dec 14, 2024
1 parent 828bd68 commit 40505cb
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 342 deletions.
8 changes: 7 additions & 1 deletion packages/scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
}
}
},
"./install-hook": {
"types": "./dist/install-hook.d.ts",
"import": "./dist/install-hook.mjs",
"require": "./dist/install-hook.js"
},
"./auto": {
"production": {
"import": {
Expand Down Expand Up @@ -234,7 +239,7 @@
"@preact/signals": "^1.3.1",
"@rollup/pluginutils": "^5.1.3",
"@types/node": "^20.17.9",
"bippy": "^0.0.14",
"bippy": "^0.0.18",
"esbuild": "^0.24.0",
"estree-walker": "^3.0.3",
"kleur": "^4.1.5",
Expand All @@ -253,6 +258,7 @@
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vercel/style-guide": "^6.0.0",
"es-module-lexer": "^1.5.4",
"eslint": "^8.0.0",
"next": "*",
"prettier": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/scan/src/auto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'bippy';
import 'bippy'; // implicit init RDT hook
import { scan } from './index';

if (typeof window !== 'undefined') {
Expand Down
47 changes: 37 additions & 10 deletions packages/scan/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { Fiber } from 'react-reconciler';
import type * as React from 'react';
import { type Signal, signal } from '@preact/signals';
import { getDisplayName, getTimings, getType, isCompositeFiber } from 'bippy';
import {
getDisplayName,
getTimings,
getType,
isCompositeFiber,
traverseFiber,
} from 'bippy';
import { createInstrumentation, type Render } from './instrumentation';
import {
type ActiveOutline,
Expand All @@ -18,11 +24,7 @@ import {
import { createToolbar } from './web/toolbar';
import type { InternalInteraction } from './monitor/types';
import { type getSession } from './monitor/utils';
import {
isValidFiber,
type RenderData,
updateFiberRenderData,
} from './utils';
import { type RenderData, updateFiberRenderData } from './utils';
import { playGeigerClickSound } from './web/geiger';

export interface Options {
Expand Down Expand Up @@ -275,6 +277,30 @@ export const reportRender = (fiber: Fiber, renders: Array<Render>) => {
}
};

export const isValidFiber = (fiber: Fiber) => {
if (ignoredProps.has(fiber.memoizedProps)) {
return false;
}

const allowList = ReactScanInternals.componentAllowList;
const shouldAllow =
allowList?.has(fiber.type) ?? allowList?.has(fiber.elementType);

if (shouldAllow) {
const parent = traverseFiber(
fiber,
(node) => {
const options =
allowList?.get(node.type) ?? allowList?.get(node.elementType);
return options?.includeChildren;
},
true,
);
if (!parent && !shouldAllow) return false;
}
return true;
};

export const start = () => {
if (typeof window === 'undefined') return;
const options = ReactScanInternals.options.value;
Expand Down Expand Up @@ -304,14 +330,15 @@ export const start = () => {
};

// TODO: dynamic enable, and inspect-off check
const instrumentation = createInstrumentation({
kind: 'devtool',
const instrumentation = createInstrumentation('devtools', {
onCommitStart() {
ReactScanInternals.options.value.onCommitStart?.();
},
isValidFiber(fiber) {
return isValidFiber(fiber);
onError(error) {
// eslint-disable-next-line no-console
console.error('[React Scan] Error instrumenting:', error);
},
isValidFiber,
onRender(fiber, renders) {
if (ReactScanInternals.instrumentation?.isPaused.value) {
// don't draw if it's paused
Expand Down
Loading

0 comments on commit 40505cb

Please sign in to comment.