Skip to content

Commit 544cd48

Browse files
chore(ci): fail CI when a file gains React effects
We are removing useEffect and its siblings from web and mobile, but nothing stops new code from adding them back as fast as they come out. scripts/effect-budget.ts parses every non-test source file under apps/ and packages/ and counts useEffect, useLayoutEffect, and useInsertionEffect calls, including React.useEffect-style member calls. scripts/effect-budget.json holds today's count per file, one sorted entry per line. CI's Lint job and check:changed fail when a file goes over its entry (a new file has 0). Counts that drop pass and print a hint; `vp run effect-budget:update` lowers entries and never raises them, so raising one is a visible manual edit in the PR that needs the effect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7bafc40 commit 544cd48

7 files changed

Lines changed: 640 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ jobs:
103103
- name: Check unused code
104104
run: vp run knip:check
105105

106+
- name: Check React effect budget
107+
run: vp run effect-budget:check
108+
106109
- name: Check generated GitHub GraphQL operations
107110
run: vp run --filter @t3tools/source-control-github generate --check
108111

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Architecture and its constraints: `docs/internals/overview.md`. Glossary: `docs/
194194
options, and pass combinators as additional function-builder arguments.
195195
- Inferred types over annotations. `any` is the enemy.
196196
- Default to no comment. Write one only for a constraint, an external quirk, or an invariant the code can't show, in one line where you can and four at most. Don't restate names or signatures, narrate steps, record history, or explain the fix you just made; the PR carries that. `t3code/no-low-value-comments` enforces the length cap and the mechanical cases.
197+
- React effects are a last resort: derive in render, act in handlers, reset with `key`, or use a ref callback or store. `scripts/effect-budget.json` fails CI when a file gains `useEffect`/`useLayoutEffect`/`useInsertionEffect` calls; raise an entry only in the PR that needs it, with a reason the reviewer can see.
197198
- Our users drive agents all day and notice a dropped frame, a lying spinner, and a stale label. No continuously repainting animations; they peg the GPU on high-refresh displays.
198199
- If a rule here fights the task in front of you, say so loudly and get a human sign-off before breaking it.
199200

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"tc": "vp run -r --cache --concurrency-limit 4 typecheck",
2929
"check:changed": "node scripts/check-changed.ts",
3030
"lint": "vp lint --report-unused-disable-directives",
31+
"effect-budget:check": "node scripts/effect-budget.ts",
32+
"effect-budget:update": "node scripts/effect-budget.ts --update",
3133
"knip": "knip --preprocessor ./scripts/knip-schemas.ts",
3234
"knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-definitions --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitcafe --workspace packages/source-control-github --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",
3335
"knip:production": "knip --production --preprocessor ./scripts/knip-schemas.ts",

‎scripts/check-changed.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @effect-diagnostics nodeBuiltinImport:off globalConsole:off
22
// Runs CI's fast checks for this branch's changes: format and lint of the
3-
// changed files, knip, generated GraphQL operations, typecheck of the affected
4-
// packages and their dependents, and the test files beside the changed files.
3+
// changed files, knip, the React effect budget, generated GraphQL operations,
4+
// typecheck of the affected packages and their dependents, and the test files
5+
// beside the changed files.
56
// A dependency change also gets the unused-patch install check below. CI still
67
// runs the full test suites and the jobs listed in the summary.
78
//
@@ -222,6 +223,13 @@ const graphql = ["apps/server", "packages/source-control-github"].filter((dir) =
222223
files.some((file) => file.startsWith(`${dir}/`)),
223224
);
224225

226+
// The effect budget reads only source files and its JSON, in about a second.
227+
const runEffectBudget = files.some(
228+
(file) =>
229+
(CODE.test(file) && (file.startsWith("apps/") || file.startsWith("packages/"))) ||
230+
file.startsWith("scripts/effect-budget."),
231+
);
232+
225233
const filters = (names: ReadonlyArray<string>) => names.flatMap((name) => ["--filter", name]);
226234
const steps = [
227235
// Runs first; it takes about a second.
@@ -232,6 +240,7 @@ const steps = [
232240
},
233241
code.length > 0 && { name: "lint", args: ["lint", ...code] },
234242
...(runKnip ? knipPasses : []),
243+
runEffectBudget && { name: "effect budget", args: ["run", "effect-budget:check"] },
235244
...graphql.map((dir) => ({
236245
name: `graphql (${dir})`,
237246
args: ["run", "--filter", `./${dir}`, "generate", "--check"],

0 commit comments

Comments
 (0)