Skip to content

Commit f4da080

Browse files
chore(web): React compiler rules apply to every web file (#20791)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 73af712 commit f4da080

5 files changed

Lines changed: 19 additions & 125 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 0 additions & 101 deletions
This file was deleted.

apps/web/src/reactCompiledFiles.test.ts renamed to apps/web/src/reactCompilerCoverage.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ import * as NodePath from "node:path";
44
import * as NodeURL from "node:url";
55
import { transform } from "oxc-transform-react";
66
import { describe, expect, it } from "vite-plus/test";
7-
import { REACT_COMPILED_FILES } from "../reactCompiledFiles";
87

98
const repoRoot = NodePath.resolve(
109
NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)),
1110
"../../..",
1211
);
1312

14-
function expandPattern(pattern: string): string[] {
15-
if (!pattern.endsWith("/**")) return [pattern];
16-
const directory = pattern.slice(0, -3);
17-
return NodeFS.readdirSync(NodePath.join(repoRoot, directory), { recursive: true })
18-
.map(String)
19-
.filter((file) => /\.tsx?$/.test(file) && !/\.(test|browser)\.tsx?$/.test(file))
20-
.map((file) => `${directory}/${file}`);
21-
}
13+
const webSourceFiles = NodeFS.readdirSync(NodePath.join(repoRoot, "apps/web/src"), {
14+
recursive: true,
15+
})
16+
.map(String)
17+
.filter((file) => /\.tsx?$/.test(file) && !/\.(test|browser)\.tsx?$/.test(file))
18+
.filter((file) => !file.endsWith(".gen.ts"))
19+
.map((file) => `apps/web/src/${file}`);
2220

2321
// Lint reports most compiler bailouts, but not every one (try/finally, throw
2422
// inside try). A skipped file still builds, just unmemoized, so check the output.
2523
describe("React Compiler coverage", () => {
26-
it.each(REACT_COMPILED_FILES.flatMap(expandPattern))("compiles %s", async (file) => {
24+
it.each(webSourceFiles)("compiles %s", async (file) => {
2725
const absolute = NodePath.join(repoRoot, file);
2826
const result = await transform(absolute, NodeFS.readFileSync(absolute, "utf8"), {
2927
jsx: { runtime: "automatic", development: false, refresh: false },

‎apps/web/tsconfig.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"vite",
3131
"vite.config.ts",
3232
"vercel.ts",
33-
"reactCompiledFiles.ts",
3433
"test",
3534
"scripts/warm-dep-cache.ts",
3635
"../../scripts/lib/public-config.ts",

‎docs/internals/web-ui.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ Anything it can't prove, such as reading a ref during render or calling `setStat
6161
makes it skip the whole function without a build error. Lint reports each skip as a
6262
`react(...)` warning with the note "React Compiler skipped optimizing this component or hook".
6363

64-
Files listed in [`reactCompiledFiles.ts`](../../apps/web/reactCompiledFiles.ts) must compile.
65-
Lint makes those rules errors there, and `t3code/no-manual-memo` rejects `useMemo` and
66-
`useCallback`, which the compiler makes redundant. Lint misses some bailouts, notably `try` with
67-
`finally` and `throw` inside `try`, so [`reactCompiledFiles.test.ts`](../../apps/web/src/reactCompiledFiles.test.ts)
68-
compiles each listed file and fails on any skip. Async handlers rarely need `try`: an atom
69-
command settles into a result, so cleanup can follow the `await`. `useStableCallback` still marks
70-
handlers that leave a large component, as described above. Add a file to the list once it
71-
compiles cleanly, and drop its manual memoization in the same change.
64+
Every file under `apps/web/src` must compile. Lint makes those rules errors there, and
65+
`t3code/no-manual-memo` rejects `useMemo` and `useCallback`, which the compiler makes redundant;
66+
no upstream rule bans them outright. Lint misses some bailouts, notably `try` with `finally` and
67+
`throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)
68+
compiles every file and fails on any skip. Async handlers rarely need `try`: an
69+
atom command settles into a result, so cleanup can follow the `await`. `useStableCallback` still
70+
marks handlers that leave a large component, as described above.

‎vite.config.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "vite-plus/test/config";
22
import { defineConfig } from "vite-plus";
33
import * as NodeURL from "node:url";
4-
import { REACT_COMPILED_FILES } from "./apps/web/reactCompiledFiles.ts";
54

65
const RESTRICTED_IMPORT_PATHS = [
76
{
@@ -322,10 +321,10 @@ export default defineConfig({
322321
},
323322
},
324323
{
325-
// Files the React Compiler must compile. Its bailout rules are errors here, and manual
326-
// memoization is redundant. apps/web/src/compiledFiles.test.ts compiles each file and
327-
// fails on any bailout lint cannot see, such as try/finally.
328-
files: [...REACT_COMPILED_FILES],
324+
// Every web file must compile under the React Compiler. Its bailout rules are errors here,
325+
// and manual memoization is redundant. No upstream rule bans useMemo/useCallback, hence
326+
// t3code/no-manual-memo.
327+
files: ["apps/web/src/**/*.{ts,tsx}"],
329328
rules: {
330329
"react/exhaustive-effect-dependencies": "error",
331330
"react/globals": "error",

0 commit comments

Comments
 (0)