@samitouri / QOS-React / commits / 705268dcd1

Fix require('ReactFeatureFlags') in eslint-plugin-react-hooks www build (#36243)

PR #35951 added FB_WWW_DEV builds for eslint-plugin-react-hooks to get www-specific feature flag values. However, the FB_WWW build uses the full ReactFeatureFlags.www.js fork, which contains: const dynamicFeatureFlags = require('ReactFeatureFlags'); This is a www Haste module that only exists in the www runtime. Rollup can't tree-shake CJS require() calls (they're assumed side-effectful), so the bare require('ReactFeatureFlags') survives in the build output even though the eslint plugin only uses the static eprh_* exports. When the built artifact is synced to www at scripts/lint/eslint/rules/eslint-plugin-react-hooks/index.js, Node.js fails with "Cannot find module 'ReactFeatureFlags'" because Haste modules aren't available in the Node.js lint environment. Create a dedicated fork (ReactFeatureFlags.eslint-plugin.www.js) that exports only the static eprh_* flags with www values, without the require('ReactFeatureFlags') dependency. Wire it up in forks.js for the eslint-plugin-react-hooks entry point. <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> Co-authored-by: Eugene Choi <eugenechoi@meta.com>

Eugene Choi committed Apr 9, 2026 at 12:14 UTC 705268dcd16779b1f51f234cebaa588d761202ce
3 files changed +38 -3
packages/shared/forks/ReactFeatureFlags.eslint-plugin.www.js new
+24
@@ -0,0 +1,24 @@
1 +/**
2 + * Copyright (c) Meta Platforms, Inc. and affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow strict
8 + */
9 +
10 +// This fork provides www-specific feature flag values for
11 +// eslint-plugin-react-hooks without pulling in the full
12 +// ReactFeatureFlags.www.js fork. The full fork imports dynamic flags
13 +// via require('ReactFeatureFlags'), which is a www Haste module that
14 +// doesn't exist in Node.js environments where the ESLint plugin runs.
15 +//
16 +// Only eprh_* flags are needed by the ESLint plugin.
17 +
18 +export const eprh_enableUseKeyedStateCompilerLint: boolean = true;
19 +export const eprh_enableVerboseNoSetStateInEffectCompilerLint: boolean = true;
20 +export const eprh_enableExhaustiveEffectDependenciesCompilerLint:
21 + | 'off'
22 + | 'all'
23 + | 'extra-only'
24 + | 'missing-only' = 'extra-only';
packages/shared/forks/ReactFeatureFlags.www.js
+6 -3
@@ -114,13 +114,16 @@ export const enableFragmentRefsInstanceHandles: boolean = true;
114
115 export const enableOptimisticKey: boolean = false;
116
117 -export const eprh_enableUseKeyedStateCompilerLint: boolean = true;
118 -export const eprh_enableVerboseNoSetStateInEffectCompilerLint: boolean = true;
117 +// These flags are only used by eslint-plugin-react-hooks, which has its own
118 +// fork at ReactFeatureFlags.eslint-plugin.www.js with the www-specific values.
119 +// Edit that file to change the www values for these flags.
120 +export const eprh_enableUseKeyedStateCompilerLint: boolean = false;
121 +export const eprh_enableVerboseNoSetStateInEffectCompilerLint: boolean = false;
122 export const eprh_enableExhaustiveEffectDependenciesCompilerLint:
123 | 'off'
124 | 'all'
125 | 'extra-only'
123 - | 'missing-only' = 'extra-only';
126 + | 'missing-only' = 'off';
127
128 // Flow magic to verify the exports of this file match the original version.
129 ((((null: any): ExportsType): FeatureFlagsType): ExportsType);
scripts/rollup/forks.js
+8
@@ -163,6 +163,14 @@ const forks = Object.freeze({
163 `Unexpected entry (${entry}) and bundleType (${bundleType})`
164 );
165 }
166 + case 'eslint-plugin-react-hooks/src/index.ts':
167 + switch (bundleType) {
168 + case FB_WWW_DEV:
169 + case FB_WWW_PROD:
170 + case FB_WWW_PROFILING:
171 + return './packages/shared/forks/ReactFeatureFlags.eslint-plugin.www.js';
172 + }
173 + return null;
174 case 'react-test-renderer':
175 switch (bundleType) {
176 case RN_FB_DEV: