From 160957353bbb827f2932dcbe052418d306bcf440 Mon Sep 17 00:00:00 2001 From: Matthew Costabile Date: Mon, 6 Jul 2026 16:29:14 +0000 Subject: [PATCH] React Compiler migration prep: REACT_COMPILER_ALL flag + skip test/story files; remove dead react-compiler eslint override --- eslint.config.mjs | 15 +++++++-------- packages/react/script/react-compiler.mjs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 37c4c0adeb0..ca1c13a5651 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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' @@ -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]), diff --git a/packages/react/script/react-compiler.mjs b/packages/react/script/react-compiler.mjs index 184c468cfc0..a575285f925 100644 --- a/packages/react/script/react-compiler.mjs +++ b/packages/react/script/react-compiler.mjs @@ -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) }