From 0b39c1fc5bdeb441d725ecec1953d0ef054966ec Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 9 Apr 2025 13:50:18 -0400 Subject: [PATCH] [eprh] Temporarily disable ref access in render validation This rule currently has a few false positives, so let's disable it for now (just in the eslint rule, it's still enabled in the compiler) while we iterate on it. --- .../__tests__/ReactCompilerRule-test.ts | 28 ------------------- .../src/rules/ReactCompilerRule.ts | 13 +++++++-- .../__tests__/ReactCompilerRule-test.ts | 28 ------------------- .../src/rules/ReactCompiler.ts | 13 +++++++-- 4 files changed, 20 insertions(+), 62 deletions(-) diff --git a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts index ea5c30d5b27f0..8f1612f20ea7a 100644 --- a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts +++ b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts @@ -92,36 +92,8 @@ const tests: CompilerTestCases = { } `, }, - { - // Don't report the issue if Flow already has - name: '[InvalidInput] Ref access during render', - code: normalizeIndent` - function Component(props) { - const ref = useRef(null); - // $FlowFixMe[react-rule-unsafe-ref] - const value = ref.current; - return value; - } - `, - }, ], invalid: [ - { - name: '[InvalidInput] Ref access during render', - code: normalizeIndent` - function Component(props) { - const ref = useRef(null); - const value = ref.current; - return value; - } - `, - errors: [ - { - message: - 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', - }, - ], - }, { name: 'Reportable levels can be configured', options: [{reportableLevels: new Set([ErrorSeverity.Todo])}], diff --git a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts index 3f778deee47b2..e9eee26bdabc6 100644 --- a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts +++ b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts @@ -105,6 +105,9 @@ const COMPILER_OPTIONS: Partial = { panicThreshold: 'none', // Don't emit errors on Flow suppressions--Flow already gave a signal flowSuppressions: false, + environment: validateEnvironmentConfig({ + validateRefAccessDuringRender: false, + }), }; const rule: Rule.RuleModule = { @@ -149,10 +152,14 @@ const rule: Rule.RuleModule = { } let shouldReportUnusedOptOutDirective = true; - const options: PluginOptions = { - ...parsePluginOptions(userOpts), + const options: PluginOptions = parsePluginOptions({ ...COMPILER_OPTIONS, - }; + ...userOpts, + environment: { + ...COMPILER_OPTIONS.environment, + ...userOpts.environment, + }, + }); const userLogger: Logger | null = options.logger; options.logger = { logEvent: (filename, event): void => { diff --git a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts index f0d14494b9671..30762e5819535 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts +++ b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts @@ -94,36 +94,8 @@ const tests: CompilerTestCases = { } `, }, - { - // Don't report the issue if Flow already has - name: '[InvalidInput] Ref access during render', - code: normalizeIndent` - function Component(props) { - const ref = useRef(null); - // $FlowFixMe[react-rule-unsafe-ref] - const value = ref.current; - return value; - } - `, - }, ], invalid: [ - { - name: '[InvalidInput] Ref access during render', - code: normalizeIndent` - function Component(props) { - const ref = useRef(null); - const value = ref.current; - return value; - } - `, - errors: [ - { - message: - 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', - }, - ], - }, { name: 'Reportable levels can be configured', options: [{reportableLevels: new Set([ErrorSeverity.Todo])}], diff --git a/packages/eslint-plugin-react-hooks/src/rules/ReactCompiler.ts b/packages/eslint-plugin-react-hooks/src/rules/ReactCompiler.ts index c2f9d3a103438..67d5745a1c7ea 100644 --- a/packages/eslint-plugin-react-hooks/src/rules/ReactCompiler.ts +++ b/packages/eslint-plugin-react-hooks/src/rules/ReactCompiler.ts @@ -107,6 +107,9 @@ const COMPILER_OPTIONS: Partial = { panicThreshold: 'none', // Don't emit errors on Flow suppressions--Flow already gave a signal flowSuppressions: false, + environment: validateEnvironmentConfig({ + validateRefAccessDuringRender: false, + }), }; const rule: Rule.RuleModule = { @@ -151,10 +154,14 @@ const rule: Rule.RuleModule = { } let shouldReportUnusedOptOutDirective = true; - const options: PluginOptions = { - ...parsePluginOptions(userOpts), + const options: PluginOptions = parsePluginOptions({ ...COMPILER_OPTIONS, - }; + ...userOpts, + environment: { + ...COMPILER_OPTIONS.environment, + ...userOpts.environment, + }, + }); const userLogger: Logger | null = options.logger; options.logger = { logEvent: (eventFilename, event): void => {