From 64376b37974d714933886bef79bdd50317d91022 Mon Sep 17 00:00:00 2001 From: Asuka109 Date: Thu, 19 Dec 2024 15:06:25 +0800 Subject: [PATCH 1/2] feat: improve options types & add contributing guide --- .vscode/settings.json | 3 +++ CONTRIBUTING.md | 9 +++++++++ packages/scan/src/core/instrumentation.ts | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ff26bff..2c8e03a5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,8 @@ "editor.colorDecorators": true, "[css]": { "editor.formatOnSave": false + }, + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" } } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..f436cafb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# Contributing + +## Setup Repository + +1. Clone the repository. +2. `cd react-scan` to the repository. +3. Run `corepack enable` to using suitable package manager or do it manually. +4. Run `pnpm install` to install the dependencies of workspace. +5. Run `pnpm build` to build all the packages. diff --git a/packages/scan/src/core/instrumentation.ts b/packages/scan/src/core/instrumentation.ts index 584b69da..9277163c 100644 --- a/packages/scan/src/core/instrumentation.ts +++ b/packages/scan/src/core/instrumentation.ts @@ -86,12 +86,21 @@ export interface Change { export type Category = 'commit' | 'unstable' | 'unnecessary'; export interface Render { - phase: string; + // TODO: use type exported from bippy instead. + phase: 'mount' | 'update' | 'unmount'; componentName: string | null; time: number | null; count: number; + /** + * Whether the re-render occurred on a component wrapped with `React.memo()`. + */ forget: boolean; changes: Array | null; + /** + * Determine if the render is unnecessary. + * Only sampling 5% of the renders to avoid performance impact. + * Otherwise, it will be `null`. + */ unnecessary: boolean | null; didCommit: boolean; fps: number; @@ -165,7 +174,6 @@ export const getPropsChanges = (fiber: Fiber) => { const prevProps = fiber.alternate?.memoizedProps || {}; const nextProps = fiber.memoizedProps || {}; - const allKeys = new Set([ ...Object.keys(prevProps), ...Object.keys(nextProps), From 95979b6595b1f9e40f9d8d907db1f10a781e5406 Mon Sep 17 00:00:00 2001 From: Asuka109 Date: Thu, 19 Dec 2024 15:09:53 +0800 Subject: [PATCH 2/2] chore: remove useless contributing guide --- .github/CONTRIBUTING.md | 1 + CONTRIBUTING.md | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6acd8b10..19fdfae2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -5,6 +5,7 @@ ```bash git clone https://github.com/aidenybai/react-scan.git cd react-scan +corepack enable pnpm install ``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index f436cafb..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,9 +0,0 @@ -# Contributing - -## Setup Repository - -1. Clone the repository. -2. `cd react-scan` to the repository. -3. Run `corepack enable` to using suitable package manager or do it manually. -4. Run `pnpm install` to install the dependencies of workspace. -5. Run `pnpm build` to build all the packages.