You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7a7ac59
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: AGENTS.md
+82-8Lines changed: 82 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,92 @@
2
2
3
3
- MUST: Use TypeScript interfaces over types.
4
4
- MUST: Keep all types in the global scope.
5
-
- MUST: Use arrow functions over function declarations
6
-
- MUST: Never comment unless absolutely necessary.
7
-
- If the code is a hack (like a setTimeout or potentially confusing code), it must be prefixed with // HACK: reason for hack
8
-
- MUST: Use kebab-case for files
5
+
- MUST: Use arrow functions over function declarations.
6
+
- 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.
7
+
- If a hack is required (like a `setTimeout` that hides a race), prefix with `// HACK: reason for hack`.
8
+
- Do not delete descriptive comments >3 lines without confirming with the user.
9
+
- MUST: Use kebab-case for files.
9
10
- MUST: Use descriptive names for variables (avoid shorthands, or 1-2 character names).
10
-
- Example: for .map(), you can use `innerX` instead of `x`
11
-
- Example: instead of `moved` use `didPositionChange`
11
+
- Example: for `.map()`, use `innerNode` instead of `n`.
12
+
- Example: instead of `moved` use `didPositionChange`.
12
13
- MUST: Frequently re-evaluate and refactor variable names to be more accurate and descriptive.
13
-
- MUST: Do not type cast ("as") unless absolutely necessary
14
+
- MUST: Do not type cast (`as`) unless absolutely necessary.
14
15
- MUST: Remove unused code and don't repeat yourself.
15
16
- MUST: Always search the codebase, think of many solutions, then implement the most _elegant_ solution.
16
17
- MUST: Put all magic numbers in `constants.ts` using `SCREAMING_SNAKE_CASE` with unit suffixes (`_MS`, `_PX`).
17
18
- MUST: Put small, focused utility functions in `utils/` with one utility per file.
18
-
- MUST: Use Boolean over !!.
19
+
- MUST: Use `Boolean(x)` over `!!x`.
20
+
21
+
## Preact + @preact/signals Rules
22
+
23
+
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.
24
+
25
+
### Signals
26
+
27
+
- MUST: Read signals via `.value` inside JSX/effects: `signalWidget.value` not `signalWidget()`.
28
+
- MUST: Write signals atomically: `signalWidget.value = { ...signalWidget.value, dimensions: ... }`. One signal per logical slice.
29
+
- MUST: Use `useSignal(initial)` for component-local reactive state, `useComputed(() => ...)` for derived values, `useSignalEffect(() => ...)` for subscriptions/DOM imperative work.
30
+
- MUST: Wrap module-level signals exported from a tree-shaken bundle with `/* @__PURE__ */ signal(...)` so production builds can drop unused state.
31
+
- 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.
32
+
- NEVER: Mirror one signal into another inside `useSignalEffect` - find the single source of truth (compute on read).
33
+
34
+
### Effects
35
+
36
+
Before reaching for `useEffect`/`useSignalEffect`, classify the work:
37
+
38
+
- MUST: Use `useComputed` when the result is pure derived state from other signals. If no external system is touched, it is not an effect.
39
+
- 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.
40
+
- MUST: Use `useEffect(..., [])` (or `useSignalEffect` with no deps) for one-time mount/cleanup of subscriptions, timers, listeners, and `MutationObserver`s. Always return the cleanup.
41
+
- MUST: Keep each effect single-purpose - one effect, one external bridge. Split mixed-responsibility effects.
42
+
- NEVER: Use an effect just to copy one signal into another.
43
+
- NEVER: Use an effect as an event bus (watching a trigger signal to run a command). Call the action directly from the event source.
44
+
45
+
### Props
46
+
47
+
- MUST: Access props via `props.title`, not destructuring, when the prop is read inside an event handler that fires later or inside an effect.
48
+
- SHOULD: Destructure props at the top of the body for purely-rendered values (read once during render).
49
+
- NEVER: Destructure a prop that is itself a signal-driven slice if you intend to re-read it after async work.
50
+
51
+
### JSX & DOM
52
+
53
+
- MUST: Use `className` (we render via Preact's React-compat JSX in [`tsconfig.json`](tsconfig.json)`jsxImportSource: preact`).
54
+
- MUST: Combine static `className="btn"` with reactive `className={cn("btn", isActive.value && "active")}` via [`cn`](packages/scan/src/web/utils/helpers.ts).
55
+
- MUST: Read refs in `useEffect` or via the callback ref pattern - DOM refs are populated after render.
56
+
- 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`.
57
+
- SHOULD: Use `style={{ "--css-var": value }}` for dynamic CSS variables; class toggles for boolean states.
58
+
- SHOULD: Type refs as `let element: HTMLElement | null = null` with a guard.
59
+
60
+
## Build & Toolchain
61
+
62
+
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.
63
+
64
+
### Approved built dependencies
65
+
66
+
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.
67
+
68
+
### Build before test
69
+
70
+
`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).
71
+
72
+
### Playwright
73
+
74
+
`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`.
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.
16
4
17
5
## Project Structure
18
6
19
-
This is a monorepo containing several packages:
7
+
This is a pnpm 10 monorepo orchestrated by [turbo](https://turbo.build) and built on [Vite+](https://viteplus.dev) (oxlint, oxfmt, tsdown).
- 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
0 commit comments