Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Add ReactFeatureFlags support to eprh (#35951) · react/react@3cb2c42 · GitHub
Skip to content

Commit 3cb2c42

Browse files
jackpopepoteto
andauthored
Add ReactFeatureFlags support to eprh (#35951)
We're currently hardcoding experimental options to `eslint-plugin-react-hooks`. This blocks the release on features that might not be ready. This PR extends the ReactFeatureFlag infra to support flags for `eslint-plugin-react-hooks`. An alternative would be to create a separate flag system for build tools, but for now we have a small number of these and reusing existing infra seems like the simplest approach. I ran a full `yarn build` and checked the output resolved the flag values as expected: _build/oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js_ ```js var eprh_enableUseKeyedStateCompilerLint = false; var eprh_enableVerboseNoSetStateInEffectCompilerLint = false; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'off'; ``` _build/facebook-www/ESLintPluginReactHooks-dev.classic.js_ ```js var eprh_enableUseKeyedStateCompilerLint = true; var eprh_enableVerboseNoSetStateInEffectCompilerLint = true; var eprh_enableExhaustiveEffectDependenciesCompilerLint = 'extra-only'; ``` --------- Co-authored-by: lauren <lauren@anysphere.co>
1 parent c0c29e8 commit 3cb2c42

15 files changed

Lines changed: 125 additions & 33 deletions

‎.github/workflows/runtime_commit_artifacts.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ jobs:
116116
run: |
117117
sed -i -e 's/ @license React*//' \
118118
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
119+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
119120
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
120121
- name: Insert @headers into eslint plugin and react-refresh
121122
run: |
122123
sed -i -e 's/ LICENSE file in the root directory of this source tree./ LICENSE file in the root directory of this source tree.\n *\n * @noformat\n * @nolint\n * @lightSyntaxTransform\n * @preventMunge\n * @oncall react_core/' \
123124
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
125+
build/facebook-www/ESLintPluginReactHooks-dev.modern.js \
124126
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
125127
- name: Move relevant files for React in www into compiled
126128
run: |
@@ -132,9 +134,9 @@ jobs:
132134
mkdir ./compiled/facebook-www/__test_utils__
133135
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
134136
135-
# Copy eslint-plugin-react-hooks
137+
# Copy eslint-plugin-react-hooks (www build with feature flags)
136138
mkdir ./compiled/eslint-plugin-react-hooks
137-
cp build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
139+
cp ./compiled/facebook-www/ESLintPluginReactHooks-dev.modern.js \
138140
./compiled/eslint-plugin-react-hooks/index.js
139141
140142
# Move unstable_server-external-runtime.js into facebook-www
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Type declarations for shared/ReactFeatureFlags
3+
*
4+
* This allows importing from the Flow-typed ReactFeatureFlags.js file
5+
* without TypeScript errors.
6+
*/
7+
declare module 'shared/ReactFeatureFlags'{
8+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean;
9+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean;
10+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
11+
|'off'
12+
|'all'
13+
|'extra-only'
14+
|'missing-only';
15+
}

‎packages/eslint-plugin-react-hooks/src/shared/RunReactCompiler.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import type * as ESTree from 'estree';
2121
import*asHermesParserfrom'hermes-parser';
2222
import{isDeepStrictEqual}from'util';
2323
importtype{ParseResult}from'@babel/parser';
24+
import{
25+
eprh_enableUseKeyedStateCompilerLint,
26+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
27+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
28+
}from'shared/ReactFeatureFlags';
2429

2530
// Pattern for component names: starts with uppercase letter
2631
constCOMPONENT_NAME_PATTERN=/^[A-Z]/;
@@ -81,10 +86,7 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
8186
// Also handles Flow component/hook syntax transformed to FunctionDeclaration with flags
8287
if(node.type==='FunctionDeclaration'){
8388
// Check for Hermes-added flags indicating Flow component/hook syntax
84-
if(
85-
'__componentDeclaration'innode||
86-
'__hookDeclaration'innode
87-
){
89+
if('__componentDeclaration'innode||'__hookDeclaration'innode){
8890
returntrue;
8991
}
9092
constid=(nodeasESTree.FunctionDeclaration).id;
@@ -107,7 +109,10 @@ function checkTopLevelNode(node: ESTree.Node): boolean {
107109
init.type==='FunctionExpression')
108110
){
109111
constname=decl.id.name;
110-
if(COMPONENT_NAME_PATTERN.test(name)||HOOK_NAME_PATTERN.test(name)){
112+
if(
113+
COMPONENT_NAME_PATTERN.test(name)||
114+
HOOK_NAME_PATTERN.test(name)
115+
){
111116
returntrue;
112117
}
113118
}
@@ -136,10 +141,13 @@ const COMPILER_OPTIONS: PluginOptions = {
136141
validateNoCapitalizedCalls: [],
137142
validateHooksUsage: true,
138143
validateNoDerivedComputationsInEffects: true,
139-
// Temporarily enabled for internal testing
140-
enableUseKeyedState: true,
141-
enableVerboseNoSetStateInEffect: true,
142-
validateExhaustiveEffectDependencies: 'extra-only',
144+
145+
// Experimental options controlled by ReactFeatureFlags
146+
enableUseKeyedState: eprh_enableUseKeyedStateCompilerLint,
147+
enableVerboseNoSetStateInEffect:
148+
eprh_enableVerboseNoSetStateInEffectCompilerLint,
149+
validateExhaustiveEffectDependencies:
150+
eprh_enableExhaustiveEffectDependenciesCompilerLint,
143151
},
144152
};
145153

‎packages/eslint-plugin-react-hooks/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"types": ["estree-jsx", "node"],
1010
"downlevelIteration": true,
1111
"paths": {
12-
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]
12+
"babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"],
13+
"shared/*": ["../shared/*"]
1314
},
1415
"jsx": "react-jsxdev",
1516
"rootDir": "../..",

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,14 @@ export const enableAsyncDebugInfo: boolean = true;
252252
exportconstenableUpdaterTracking=__PROFILE__;
253253

254254
exportconstownerStackLimit=1e4;
255+
256+
// -----------------------------------------------------------------------------
257+
// eslint-plugin-react-hooks
258+
// -----------------------------------------------------------------------------
259+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
260+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
261+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
262+
|'off'
263+
|'all'
264+
|'extra-only'
265+
|'missing-only'='off';

‎packages/shared/forks/ReactFeatureFlags.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableInternalInstanceMap: boolean = false;
8585
exportconstenableOptimisticKey: boolean=false;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.native-oss.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ export const enableProfilerNestedUpdatePhase: boolean = __PROFILE__;
8585
exportconstenableUpdaterTracking: boolean=__PROFILE__;
8686
exportconstenableParallelTransitions: boolean=false;
8787

88+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
89+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
90+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
91+
|'off'
92+
|'all'
93+
|'extra-only'
94+
|'missing-only'='off';
95+
8896
// Flow magic to verify the exports of this file match the original version.
8997
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ export const enableObjectFiber: boolean = false;
9494
exportconstenableOptimisticKey: boolean=false;
9595
exportconstenableParallelTransitions: boolean=false;
9696

97+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
98+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
99+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
100+
|'off'
101+
|'all'
102+
|'extra-only'
103+
|'missing-only'='off';
104+
97105
// Flow magic to verify the exports of this file match the original version.
98106
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ export const ownerStackLimit = 1e4;
7171
exportconstenableOptimisticKey=false;
7272
exportconstenableParallelTransitions=false;
7373

74+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
75+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
76+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
77+
|'off'
78+
|'all'
79+
|'extra-only'
80+
|'missing-only'='off';
81+
7482
// Flow magic to verify the exports of this file match the original version.
7583
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

‎packages/shared/forks/ReactFeatureFlags.test-renderer.www.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,13 @@ export const enableInternalInstanceMap: boolean = false;
8686
exportconstenableOptimisticKey: boolean=false;
8787
exportconstenableParallelTransitions: boolean=false;
8888

89+
exportconsteprh_enableUseKeyedStateCompilerLint: boolean=false;
90+
exportconsteprh_enableVerboseNoSetStateInEffectCompilerLint: boolean=false;
91+
exportconsteprh_enableExhaustiveEffectDependenciesCompilerLint:
92+
|'off'
93+
|'all'
94+
|'extra-only'
95+
|'missing-only'='off';
96+
8997
// Flow magic to verify the exports of this file match the original version.
9098
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)