Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
101 changes: 0 additions & 101 deletions apps/web/reactCompiledFiles.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ import * as NodePath from "node:path";
import * as NodeURL from "node:url";
import { transform } from "oxc-transform-react";
import { describe, expect, it } from "vite-plus/test";
import { REACT_COMPILED_FILES } from "../reactCompiledFiles";

const repoRoot = NodePath.resolve(
NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)),
"../../..",
);

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

// Lint reports most compiler bailouts, but not every one (try/finally, throw
// inside try). A skipped file still builds, just unmemoized, so check the output.
describe("React Compiler coverage", () => {
it.each(REACT_COMPILED_FILES.flatMap(expandPattern))("compiles %s", async (file) => {
it.each(webSourceFiles)("compiles %s", async (file) => {
const absolute = NodePath.join(repoRoot, file);
const result = await transform(absolute, NodeFS.readFileSync(absolute, "utf8"), {
jsx: { runtime: "automatic", development: false, refresh: false },
Expand Down
1 change: 0 additions & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"vite",
"vite.config.ts",
"vercel.ts",
"reactCompiledFiles.ts",
"test",
"scripts/warm-dep-cache.ts",
"../../scripts/lib/public-config.ts",
Expand Down
15 changes: 7 additions & 8 deletions docs/internals/web-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ Anything it can't prove, such as reading a ref during render or calling `setStat
makes it skip the whole function without a build error. Lint reports each skip as a
`react(...)` warning with the note "React Compiler skipped optimizing this component or hook".

Files listed in [`reactCompiledFiles.ts`](../../apps/web/reactCompiledFiles.ts) must compile.
Lint makes those rules errors there, and `t3code/no-manual-memo` rejects `useMemo` and
`useCallback`, which the compiler makes redundant. Lint misses some bailouts, notably `try` with
`finally` and `throw` inside `try`, so [`reactCompiledFiles.test.ts`](../../apps/web/src/reactCompiledFiles.test.ts)
compiles each listed file and fails on any skip. Async handlers rarely need `try`: an atom
command settles into a result, so cleanup can follow the `await`. `useStableCallback` still marks
handlers that leave a large component, as described above. Add a file to the list once it
compiles cleanly, and drop its manual memoization in the same change.
Every file under `apps/web/src` must compile. Lint makes those rules errors there, and
`t3code/no-manual-memo` rejects `useMemo` and `useCallback`, which the compiler makes redundant;
no upstream rule bans them outright. Lint misses some bailouts, notably `try` with `finally` and
`throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)
compiles every file and fails on any skip. Async handlers rarely need `try`: an
atom command settles into a result, so cleanup can follow the `await`. `useStableCallback` still
marks handlers that leave a large component, as described above.
9 changes: 4 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "vite-plus/test/config";
import { defineConfig } from "vite-plus";
import * as NodeURL from "node:url";
import { REACT_COMPILED_FILES } from "./apps/web/reactCompiledFiles.ts";

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