mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[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.
This commit is contained in:
@@ -9,9 +9,9 @@ import * as t from '@babel/types';
|
||||
import {z} from 'zod';
|
||||
import {CompilerError, CompilerErrorDetailOptions} from '../CompilerError';
|
||||
import {
|
||||
EnvironmentConfig,
|
||||
ExternalFunction,
|
||||
parseEnvironmentConfig,
|
||||
PartialEnvironmentConfig,
|
||||
tryParseExternalFunction,
|
||||
} from '../HIR/Environment';
|
||||
import {hasOwnProperty} from '../Utils/utils';
|
||||
@@ -39,7 +39,7 @@ const PanicThresholdOptionsSchema = z.enum([
|
||||
export type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
|
||||
|
||||
export type PluginOptions = {
|
||||
environment: EnvironmentConfig;
|
||||
environment: PartialEnvironmentConfig;
|
||||
|
||||
logger: Logger | null;
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ import {
|
||||
CompilerErrorDetail,
|
||||
ErrorSeverity,
|
||||
} from '../CompilerError';
|
||||
import {EnvironmentConfig, ReactFunctionType} from '../HIR/Environment';
|
||||
import {
|
||||
EnvironmentConfig,
|
||||
ReactFunctionType,
|
||||
validateEnvironmentConfig,
|
||||
} from '../HIR/Environment';
|
||||
import {CodegenFunction} from '../ReactiveScopes';
|
||||
import {isComponentDeclaration} from '../Utils/ComponentDeclaration';
|
||||
import {isHookDeclaration} from '../Utils/HookDeclaration';
|
||||
@@ -291,7 +295,7 @@ export function compileProgram(
|
||||
return null;
|
||||
}
|
||||
|
||||
const environment = pass.opts.environment;
|
||||
const environment = validateEnvironmentConfig(pass.opts.environment);
|
||||
const restrictedImportsErr = validateRestrictedImports(program, environment);
|
||||
if (restrictedImportsErr) {
|
||||
handleError(restrictedImportsErr, pass, null);
|
||||
|
||||
@@ -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])}],
|
||||
|
||||
@@ -105,6 +105,9 @@ const COMPILER_OPTIONS: Partial<PluginOptions> = {
|
||||
panicThreshold: 'none',
|
||||
// Don't emit errors on Flow suppressions--Flow already gave a signal
|
||||
flowSuppressions: false,
|
||||
environment: {
|
||||
validateRefAccessDuringRender: false,
|
||||
},
|
||||
};
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
|
||||
@@ -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])}],
|
||||
|
||||
@@ -107,6 +107,9 @@ const COMPILER_OPTIONS: Partial<PluginOptions> = {
|
||||
panicThreshold: 'none',
|
||||
// Don't emit errors on Flow suppressions--Flow already gave a signal
|
||||
flowSuppressions: false,
|
||||
environment: {
|
||||
validateRefAccessDuringRender: false,
|
||||
},
|
||||
};
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
|
||||
Reference in New Issue
Block a user