Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ jobs:
fetch-depth: 0
ref: main

- name: Setup PNPM
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 9.x
node-version: '22'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pkg-pr-new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
node-version: [22]

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.1.0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ dist
build
!packages/extension/build/
playgrounds
# SSL Certificates
bin/certs/*.pem
bin/certs/*.key
.cursor
# Turbo cache
.turbo/
# Playwright
test-results/
playwright-report/
.cursor
31 changes: 0 additions & 31 deletions .oxlintrc.json

This file was deleted.

90 changes: 82 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,92 @@

- MUST: Use TypeScript interfaces over types.
- MUST: Keep all types in the global scope.
- MUST: Use arrow functions over function declarations
- MUST: Never comment unless absolutely necessary.
- If the code is a hack (like a setTimeout or potentially confusing code), it must be prefixed with // HACK: reason for hack
- MUST: Use kebab-case for files
- MUST: Use arrow functions over function declarations.
- MUST: Default to NO comments. Only add a comment when the user explicitly asks, or when the "why" is truly non-obvious - browser quirks, platform bugs, performance tradeoffs, fragile internal patching, or counter-intuitive design decisions. Never add comments that restate what the code does or what a well-named function/variable already conveys. When in doubt, leave the comment out.
- If a hack is required (like a `setTimeout` that hides a race), prefix with `// HACK: reason for hack`.
- Do not delete descriptive comments >3 lines without confirming with the user.
- MUST: Use kebab-case for files.
- MUST: Use descriptive names for variables (avoid shorthands, or 1-2 character names).
- Example: for .map(), you can use `innerX` instead of `x`
- Example: instead of `moved` use `didPositionChange`
- Example: for `.map()`, use `innerNode` instead of `n`.
- Example: instead of `moved` use `didPositionChange`.
- MUST: Frequently re-evaluate and refactor variable names to be more accurate and descriptive.
- MUST: Do not type cast ("as") unless absolutely necessary
- MUST: Do not type cast (`as`) unless absolutely necessary.
- MUST: Remove unused code and don't repeat yourself.
- MUST: Always search the codebase, think of many solutions, then implement the most _elegant_ solution.
- MUST: Put all magic numbers in `constants.ts` using `SCREAMING_SNAKE_CASE` with unit suffixes (`_MS`, `_PX`).
- MUST: Put small, focused utility functions in `utils/` with one utility per file.
- MUST: Use Boolean over !!.
- MUST: Use `Boolean(x)` over `!!x`.

## Preact + @preact/signals Rules

React Scan's overlay UI runs as a Preact app mounted inside a Shadow DOM (see [`packages/scan/src/core/index.ts`](packages/scan/src/core/index.ts)). Reactivity is driven by `@preact/signals`, not React state.

### Signals

- MUST: Read signals via `.value` inside JSX/effects: `signalWidget.value` not `signalWidget()`.
- MUST: Write signals atomically: `signalWidget.value = { ...signalWidget.value, dimensions: ... }`. One signal per logical slice.
- MUST: Use `useSignal(initial)` for component-local reactive state, `useComputed(() => ...)` for derived values, `useSignalEffect(() => ...)` for subscriptions/DOM imperative work.
- MUST: Wrap module-level signals exported from a tree-shaken bundle with `/* @__PURE__ */ signal(...)` so production builds can drop unused state.
- SHOULD: Persist user-facing state via `readLocalStorage`/`saveLocalStorage` from [`~web/utils/helpers`](packages/scan/src/web/utils/helpers.ts) and seed the signal with the persisted value.
- NEVER: Mirror one signal into another inside `useSignalEffect` - find the single source of truth (compute on read).

### Effects

Before reaching for `useEffect`/`useSignalEffect`, classify the work:

- MUST: Use `useComputed` when the result is pure derived state from other signals. If no external system is touched, it is not an effect.
- MUST: Use event handlers and direct action calls when work happens because the user clicked, dragged, or navigated. Do not watch a flag in an effect to trigger imperative logic.
- MUST: Use `useEffect(..., [])` (or `useSignalEffect` with no deps) for one-time mount/cleanup of subscriptions, timers, listeners, and `MutationObserver`s. Always return the cleanup.
- MUST: Keep each effect single-purpose - one effect, one external bridge. Split mixed-responsibility effects.
- NEVER: Use an effect just to copy one signal into another.
- NEVER: Use an effect as an event bus (watching a trigger signal to run a command). Call the action directly from the event source.

### Props

- MUST: Access props via `props.title`, not destructuring, when the prop is read inside an event handler that fires later or inside an effect.
- SHOULD: Destructure props at the top of the body for purely-rendered values (read once during render).
- NEVER: Destructure a prop that is itself a signal-driven slice if you intend to re-read it after async work.

### JSX & DOM

- MUST: Use `className` (we render via Preact's React-compat JSX in [`tsconfig.json`](tsconfig.json) `jsxImportSource: preact`).
- MUST: Combine static `className="btn"` with reactive `className={cn("btn", isActive.value && "active")}` via [`cn`](packages/scan/src/web/utils/helpers.ts).
- MUST: Read refs in `useEffect` or via the callback ref pattern - DOM refs are populated after render.
- MUST: Mount overlay UI under the existing shadow root from `initRootContainer()` in [`core/index.ts`](packages/scan/src/core/index.ts). Do not append directly to `document.body`.
- SHOULD: Use `style={{ "--css-var": value }}` for dynamic CSS variables; class toggles for boolean states.
- SHOULD: Type refs as `let element: HTMLElement | null = null` with a guard.

## Build & Toolchain

This is a pnpm 10 monorepo with `packages/*` (libraries, extension, website) and a top-level `kitchen-sink/` (Playwright target). The toolchain is [Vite+](https://viteplus.dev) (`vp lint`, `vp fmt`, `vp check`) and `turbo` for pipeline orchestration.

### Approved built dependencies

The root [`package.json`](package.json) declares `pnpm.onlyBuiltDependencies` for `@parcel/watcher`, `esbuild`, `sharp`, `spawn-sync`, `unrs-resolver`. Without this list, `pnpm install` skips their native build steps and downstream packages fail.

### Build before test

`pnpm build` must complete before `pnpm test`, `pnpm test:e2e`, or `pnpm lint`. After modifying source files, always rebuild before running tests. Turbo enforces this via `dependsOn: ["^build"]` in [`turbo.json`](turbo.json).

### Playwright

`pnpm test:e2e` runs Playwright against the `kitchen-sink` Vite dev server on port 5173 (auto-started by [`playwright.config.ts`](playwright.config.ts)). Chromium must be installed: `npx playwright install chromium --with-deps`.

### Key commands

| Task | Command |
| -------------- | -------------------------------------------- |
| Install | `pnpm install` |
| Build | `pnpm build` |
| Dev watch | `pnpm dev` (watches `react-scan` + kitchen-sink) |
| Unit tests | `pnpm test` |
| E2E tests | `pnpm test:e2e` |
| Lint | `pnpm lint` (oxlint via vite-plus) |
| Lint + fix | `pnpm lint:fix` |
| Format | `pnpm format` (oxfmt via vite-plus) |
| Format check | `pnpm format:check` |
| Typecheck | `pnpm typecheck` |
| Combined | `pnpm check` (lint + fmt check + typecheck) |

## Testing

Expand All @@ -25,4 +97,6 @@ Run checks always before committing with:
pnpm build
pnpm lint
pnpm format
pnpm typecheck
pnpm test:e2e
```
33 changes: 0 additions & 33 deletions BROWSER_EXTENSION_GUIDE.md

This file was deleted.

146 changes: 78 additions & 68 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,105 @@
# Contributing to React Scan

First off, thanks for taking the time to contribute! ❤️

## Table of Contents

- [Contributing to React Scan](#contributing-to-react-scan)
- [Table of Contents](#table-of-contents)
- [Project Structure](#project-structure)
- [Development Setup](#development-setup)
- [Contributing Guidelines](#contributing-guidelines)
- [Commits](#commits)
- [Pull Request Process](#pull-request-process)
- [Development Workflow](#development-workflow)
- [Getting Help](#getting-help)
Thanks for your interest in contributing to React Scan! This document covers the project layout, dev setup, and the workflow for getting your change merged.

## Project Structure

This is a monorepo containing several packages:
This is a pnpm 10 monorepo orchestrated by [turbo](https://turbo.build) and built on [Vite+](https://viteplus.dev) (oxlint, oxfmt, tsdown).

```
packages/
├── scan/ # Core React Scan library + CLI
├── extension/ # Browser extension (Chrome / Firefox / Brave)
├── vite-plugin-react-scan/ # Vite plugin wrapper
└── website/ # Marketing site (Next.js, react-scan.com)

- `packages/scan` - Core React Scan package
- `packages/vite-plugin-react-scan` - Vite plugin for React Scan
- `packages/extension` - VS Code extension
kitchen-sink/ # Playwright target app (Vite, port 5173)
e2e/ # Playwright specs
docs/installation/ # Per-framework install guides
```

## Development Setup

1. **Clone and Install**
```bash
git clone https://github.com/aidenybai/react-scan.git
cd react-scan
pnpm install
```
### Prerequisites

2. **Build all packages**
```bash
pnpm build
```
- Node.js >= 22
- pnpm >= 10

3. **Testing React Scan**
```bash
cd packages/scan
pnpm build:copy
```
- This will build the package and then copy it to your clipboard as an IIFE (immedietely invoked function expression). This will allow you to paste it into the browser console to test it on any website
### Setup

https://github.com/user-attachments/assets/f279e664-479f-4e39-bff4-1bbfee30af22
```bash
git clone https://github.com/aidenybai/react-scan.git
cd react-scan
pnpm install
pnpm build
```

## Contributing Guidelines
### Dev workflow

### Commits
```bash
pnpm dev # watches react-scan + kitchen-sink in parallel
pnpm --filter react-scan build:copy # build and copy IIFE to clipboard for ad-hoc testing
pnpm --filter @react-scan/extension dev # extension in Chrome
pnpm --filter @react-scan/website dev # marketing site
```

We use conventional commits to ensure consistent commit messages:
## Code Style

- `feat:` New features
- `fix:` Bug fixes
- `docs:` Documentation changes
- `chore:` Maintenance tasks
- `test:` Adding or updating tests
- `refactor:` Code changes that neither fix bugs nor add features
We use [Vite+](https://viteplus.dev) which bundles oxlint and oxfmt. See [`AGENTS.md`](AGENTS.md) for the full rule set.

```bash
pnpm lint # check
pnpm lint:fix # auto-fix
pnpm format # write
pnpm format:check # verify
pnpm check # lint + format:check + typecheck
pnpm typecheck
```

Highlights:

- TypeScript everywhere; avoid `any`.
- Interfaces over types; kebab-case filenames.
- Arrow functions over function declarations.
- No comments unless the "why" is non-obvious. Hacks must be prefixed with `// HACK: …`.
- Magic numbers in `constants.ts` with `_MS` / `_PX` unit suffixes.
- One utility per file under `utils/`.

## Tests

Example: `fix(scan): fix a typo`
```bash
pnpm test # vitest in each package
pnpm test:e2e # Playwright against kitchen-sink (auto-started on :5173)
pnpm test:e2e:ui # Playwright UI mode
```

### Pull Request Process
## Pull Requests

1. Fork the repository
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
3. Commit your changes using conventional commits
4. Push to your branch
5. Open a Pull Request
6. Ask for reviews (@pivanov, @RobPruzan are your friends in this journey)
1. Fork and create a branch (`git checkout -b feat/your-feature`).
2. Make your changes; run `pnpm check` and `pnpm test:e2e` before pushing.
3. If your change affects a published package, add a changeset:
```bash
pnpm changeset
```
4. Open a PR against `main`. Tag [@aidenybai](https://github.com/aidenybai) for review.

### Development Workflow
### Commit Convention

1. **TypeScript**
- All code must be written in TypeScript
- Ensure strict type checking passes
- No `any` types unless absolutely necessary
We use conventional commits:

2. **Code Style**
- We use Biome for formatting and linting
- Run `pnpm format` to format code
- Run `pnpm lint` to check for issues
- `feat:` New features
- `fix:` Bug fixes
- `docs:` Documentation
- `chore:` Maintenance
- `refactor:` Code changes that neither fix bugs nor add features
- `test:` Tests

3. **Documentation**
- Update relevant documentation
- Add JSDoc comments for public APIs
- Update README if needed
Example: `fix(scan): handle null fiber in flash overlay`

## Getting Help
- Check existing issues
- Create a new issue

<br />
- Check existing [issues](https://github.com/aidenybai/react-scan/issues)
- Open a new issue with a minimal repro
- Join our [Discord](https://discord.gg/KV3FhDq7FA)

⚛️ Happy coding! 🚀
Happy contributing!
Loading
Loading