Skip to content
Closed
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
15 changes: 7 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefreshPlugin from 'eslint-plugin-react-refresh'
import reactYouMightNotNeedAnEffect from 'eslint-plugin-react-you-might-not-need-an-effect'
import {unsupportedPatterns as reactCompilerUnsupported} from './packages/react/script/react-compiler.mjs'
import playwright from 'eslint-plugin-playwright'
import prettierRecommended from 'eslint-plugin-prettier/recommended'
import primerReact from 'eslint-plugin-primer-react'
Expand Down Expand Up @@ -77,13 +76,13 @@ const config = defineConfig([
],
},
},
// Disable react-compiler rule for files not yet migrated
{
files: reactCompilerUnsupported.map(p => `packages/react/${p}`),
rules: {
'react-compiler/react-compiler': 'off',
},
},
// Note: React Compiler lint diagnostics are enforced repo-wide by
// eslint-plugin-react-hooks `recommended-latest` (the granular `react-hooks/*`
// rules, e.g. `set-state-in-effect`, `immutability`, `refs`, `purity`). The old
// monolithic `react-compiler/react-compiler` rule no longer exists (that plugin
// is not installed), so there is no per-file compiler-rule override here. Which
// files actually get compiled/memoized is gated separately by `isSupported` in
// packages/react/script/react-compiler.mjs.

...fixupConfigRules([github.browser, github.recommended, github.react]),

Expand Down
15 changes: 15 additions & 0 deletions packages/react/script/react-compiler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ const unsupported = new Set(
)

function isSupported(filepath) {
// Never compile test or story files: they aren't shipped, often define ad-hoc
// helper components that violate the Rules of React (which makes the compiler
// inject hooks into non-components and throw "invalid hook call"), and gain
// nothing from memoization. Excluding them also keeps a component's test suite
// green when the component itself is migrated.
if (/\.(test|stories)\.[cm]?[jt]sx?$/.test(filepath)) {
return false
}
// Opt-in override to compile ALL (non-test) source files, including the
// not-yet-migrated ones, so the full test suite can validate a bulk React
// Compiler migration. Enable with REACT_COMPILER_ALL=true
// (e.g. `REACT_COMPILER_ALL=true npm test`).
if (process.env.REACT_COMPILER_ALL === 'true') {
return true
}
return !unsupported.has(filepath)
}

Expand Down
Loading