Skip to content

Commit

Permalink
add scan
Browse files Browse the repository at this point in the history
  • Loading branch information
pivanov committed Jan 6, 2025
1 parent c8d94dc commit 8963fa6
Show file tree
Hide file tree
Showing 83 changed files with 12,556 additions and 43 deletions.
12 changes: 5 additions & 7 deletions packages/bippy/src/rdt-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ export const getRDTHook = (onActive?: () => unknown) => {
try {
// __REACT_DEVTOOLS_GLOBAL_HOOK__ must exist before React is ever executed
if (
typeof window !== "undefined" &&
// @ts-expect-error `document` may not be defined in some enviroments
(window.document?.createElement ||
window.navigator?.product === "ReactNative") &&
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
(typeof window.document.createElement === 'function' ||
(typeof window.navigator !== 'undefined' &&
window.navigator.product === 'ReactNative'))
) {
installRDTHook();
}
Expand Down
7 changes: 7 additions & 0 deletions packages/bippy/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export interface ReactRenderer {
version: string;
bundleType: 0 /* PROD */ | 1 /* DEV */;
findFiberByHostInstance?: (hostInstance: unknown) => Fiber | null;
overrideProps?: (fiber: Fiber, path: unknown[], value: unknown) => void;
overrideHookState?: (
fiber: Fiber,
id: unknown,
path: unknown[],
value: unknown,
) => void;
}

export interface ContextDependency<T> {
Expand Down
19 changes: 18 additions & 1 deletion packages/bippy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"jsx": "react",
"module": "ESNext",
"target": "ESNext",
"esModuleInterop": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"lib": [
"esnext",
"dom"
],
"moduleResolution": "bundler"
},
"include": [
"src",
"vitest.config.ts",
"tsup.config.ts"
],
"exclude": [
"**/node_modules/**",
"dist"
]
}
55 changes: 55 additions & 0 deletions packages/scan/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@bippy/scan",
"private": true,
"type": "module",
"main": "../bippy/dist/scan/index.js",
"module": "../bippy/dist/scan/index.js",
"types": "../bippy/dist/scan/index.d.ts",
"scripts": {
"dev": "NODE_ENV=development vite build --watch",
"build": "vite build",
"dev2": "vite"
},
"dependencies": {
"@preact/signals": "^1.3.1",
"bippy": "workspace:*",
"preact": "^10.25.1"
},
"devDependencies": {
"@pivanov/vite-plugin-svg-sprite": "3.0.0-rc-0.0.10",
"@remix-run/react": "*",
"@types/rollup": "^0.54.0",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"next": "*",
"postcss": "^8.4.49",
"react": "*",
"react-dom": "*",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0 || ^6.0.0 || ^7.0.0",
"rollup": "^4.29.1",
"tailwind-merge": "^2.6.0",
"tailwindcss": "^3.4.17",
"vite": "^6.0.7",
"vite-plugin-dts": "^4.4.0",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^2.1.8"
},
"peerDependenciesMeta": {
"@remix-run/react": {
"optional": true
},
"next": {
"optional": true
},
"react-router": {
"optional": true
},
"react-router-dom": {
"optional": true
}
},
"optionalDependencies": {
"unplugin": "2.1.0"
}
}
6 changes: 6 additions & 0 deletions packages/scan/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
27 changes: 27 additions & 0 deletions packages/scan/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## todo

- think of ways to highlight what the actual problems are
- service worker
- port over select tool

## notes

- feature compat with existing version (core, instrumentation, highlighting)
- refactor main website
- playwright version

# react scan v1 architecture

- `bippy` / `@react-scan/web-vitals`
- `@react-scan/web-instrumentation`: web instrumentation, export API for renders, types of renders, FPS, CWV
- `react-scan`:
- web highlighting overlay
- web toolbar
- `@react-scan/playwright`:
- playwright plugin (... for each testing lib)
- `@react-scan/sdk`:
- observability sdk
- `@react-scan/native-instrumentation`: native instrumentation, export API for renders, types of renders, FPS, CWV
- `@react-scan/native`:
- native highlighting overlay
- native toolbar
6 changes: 6 additions & 0 deletions packages/scan/src/astro.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="astro/client" />

declare module '*.astro' {
const Component: unknown;
export default Component;
}
62 changes: 62 additions & 0 deletions packages/scan/src/core/fast-serialize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, it, expect } from 'vitest';
import { fastSerialize } from '~core/instrumentation';

describe('fastSerialize', () => {
it('serializes null', () => {
expect(fastSerialize(null)).toBe('null');
});

it('serializes undefined', () => {
expect(fastSerialize(undefined)).toBe('undefined');
});

it('serializes strings', () => {
expect(fastSerialize('hello')).toBe('hello');
expect(fastSerialize('')).toBe('');
});

it('serializes numbers', () => {
expect(fastSerialize(42)).toBe('42');
expect(fastSerialize(0)).toBe('0');
expect(fastSerialize(Number.NaN)).toBe('NaN');
});

it('serializes booleans', () => {
expect(fastSerialize(true)).toBe('true');
expect(fastSerialize(false)).toBe('false');
});

it('serializes functions', () => {
const testFunc = (_x: 2) => 3
expect(fastSerialize(testFunc)).toBe('(_x) => 3');
});

it('serializes arrays', () => {
expect(fastSerialize([])).toBe('[]');
expect(fastSerialize([1, 2, 3])).toBe('[3]');
});

it('serializes plain objects', () => {
expect(fastSerialize({})).toBe('{}');
expect(fastSerialize({ a: 1, b: 2 })).toBe('{2}');
});

it('serializes deeply nested objects with depth limit', () => {
const nested = { a: { b: { c: 1 } } };
expect(fastSerialize(nested, 0)).toBe('{1}');
expect(fastSerialize(nested, -1)).toBe('…');
});

it('serializes objects with custom constructors', () => {
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class CustomClass {}
const instance = new CustomClass();
expect(fastSerialize(instance)).toBe('CustomClass{…}');
});

it('serializes unknown objects gracefully', () => {
const date = new Date();
const serialized = fastSerialize(date);
expect(serialized.includes('Date')).toBe(true);
});
});
Loading

0 comments on commit 8963fa6

Please sign in to comment.