[compiler] Cleanup diagnostic messages

Minor sytlistic cleanup
This commit is contained in:
Joe Savona
2025-07-11 16:19:12 -07:00
parent c5a10aad9a
commit 00a89ec51f
311 changed files with 603 additions and 643 deletions
@@ -84,7 +84,9 @@ export default function BabelPluginReactCompiler(
}
} catch (e) {
if (e instanceof CompilerError) {
throw new Error(e.printErrorMessage(pass.file.code));
throw new Error(
e.printErrorMessage(pass.file.code, {eslint: false}),
);
}
throw e;
}
@@ -93,6 +93,14 @@ export type CompilerErrorDetailOptions = {
suggestions?: Array<CompilerSuggestion> | null | undefined;
};
export type PrintErrorMessageOptions = {
/**
* ESLint uses 1-indexed columns and prints one error at a time
* So it doesn't require the "Found # error(s)" text
*/
eslint: boolean;
};
export class CompilerDiagnostic {
options: CompilerDiagnosticOptions;
@@ -128,7 +136,7 @@ export class CompilerDiagnostic {
return this.options.details.filter(d => d.kind === 'error')[0]?.loc ?? null;
}
printErrorMessage(source: string): string {
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
const buffer = [
printErrorSummary(this.severity, this.category),
'\n\n',
@@ -162,9 +170,14 @@ export class CompilerDiagnostic {
} catch (e) {
codeFrame = detail.message;
}
buffer.push(
`\n\n${loc.filename}:${loc.start.line}:${loc.start.column}\n`,
);
buffer.push('\n\n');
if (loc.filename != null) {
const line = loc.start.line;
const column = options.eslint
? loc.start.column + 1
: loc.start.column;
buffer.push(`${loc.filename}:${line}:${column}\n`);
}
buffer.push(codeFrame);
break;
}
@@ -223,7 +236,7 @@ export class CompilerErrorDetail {
return this.loc;
}
printErrorMessage(source: string): string {
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
const buffer = [printErrorSummary(this.severity, this.reason)];
if (this.description != null) {
buffer.push(`\n\n${this.description}.`);
@@ -251,9 +264,12 @@ export class CompilerErrorDetail {
} catch (e) {
codeFrame = '';
}
buffer.push(
`\n\n${loc.filename}:${loc.start.line}:${loc.start.column}\n`,
);
buffer.push(`\n\n`);
if (loc.filename != null) {
const line = loc.start.line;
const column = options.eslint ? loc.start.column + 1 : loc.start.column;
buffer.push(`${loc.filename}:${line}:${column}\n`);
}
buffer.push(codeFrame);
buffer.push('\n\n');
}
@@ -372,10 +388,15 @@ export class CompilerError extends Error {
return this.name;
}
printErrorMessage(source: string): string {
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
if (options.eslint && this.details.length === 1) {
return this.details[0].printErrorMessage(source, options);
}
return (
`Found ${this.details.length} error${this.details.length === 1 ? '' : 's'}:\n` +
this.details.map(detail => detail.printErrorMessage(source)).join('\n')
`Found ${this.details.length} error${this.details.length === 1 ? '' : 's'}:\n\n` +
this.details
.map(detail => detail.printErrorMessage(source, options).trim())
.join('\n\n')
);
}
@@ -107,10 +107,9 @@ export function lower(
if (binding.kind !== 'Identifier') {
builder.errors.pushDiagnostic(
CompilerDiagnostic.create({
category: 'Could not find binding',
description: `[BuildHIR] Could not find binding for param \`${param.node.name}\``,
severity: ErrorSeverity.Invariant,
suggestions: null,
category: 'Could not find binding',
description: `[BuildHIR] Could not find binding for param \`${param.node.name}\`.`,
}).withDetail({
kind: 'error',
loc: param.node.loc ?? null,
@@ -172,10 +171,9 @@ export function lower(
} else {
builder.errors.pushDiagnostic(
CompilerDiagnostic.create({
category: `Handle ${param.node.type} parameters`,
description: `[BuildHIR] Add support for ${param.node.type} parameters`,
severity: ErrorSeverity.Todo,
suggestions: null,
category: `Handle ${param.node.type} parameters`,
description: `[BuildHIR] Add support for ${param.node.type} parameters.`,
}).withDetail({
kind: 'error',
loc: param.node.loc ?? null,
@@ -205,8 +203,7 @@ export function lower(
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidJS,
category: `Unexpected function body kind`,
description: `Expected function body to be an expression or a block statement, got \`${body.type}\``,
suggestions: null,
description: `Expected function body to be an expression or a block statement, got \`${body.type}\`.`,
}).withDetail({
kind: 'error',
loc: body.node.loc ?? null,
@@ -447,23 +447,22 @@ function applySignature(
reason: value.reason,
context: new Set(),
});
const message =
const variable =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `\`${effect.value.identifier.name.value}\` cannot be modified`
: 'This value cannot be modified';
? `\`${effect.value.identifier.name.value}\``
: 'value';
effects.push({
kind: 'MutateFrozen',
place: effect.value,
error: CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'This value cannot be modified',
description: reason,
suggestions: null,
description: `${reason}.`,
}).withDetail({
kind: 'error',
loc: effect.value.loc,
message,
message: `${variable} cannot be modified`,
}),
});
}
@@ -1018,30 +1017,30 @@ function applyEffect(
effect.value.identifier.declarationId,
)
) {
const description =
const variable =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `Variable \`${effect.value.identifier.name.value}\``
: 'This variable';
? `\`${effect.value.identifier.name.value}\``
: null;
const hoistedAccess = context.hoistedContextDeclarations.get(
effect.value.identifier.declarationId,
);
const diagnostic = CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot access variable before it is declared',
description: `${description} is accessed before it is declared, which prevents the earlier access from updating when this value changes over time`,
description: `${variable ?? 'This variable'} is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.`,
});
if (hoistedAccess != null && hoistedAccess.loc != effect.value.loc) {
diagnostic.withDetail({
kind: 'error',
loc: hoistedAccess.loc,
message: 'Variable accessed before it is declared',
message: `${variable ?? 'variable'} accessed before it is declared`,
});
}
diagnostic.withDetail({
kind: 'error',
loc: effect.value.loc,
message: 'The variable is declared here',
message: `${variable ?? 'variable'} is declared here`,
});
applyEffect(
@@ -1061,11 +1060,11 @@ function applyEffect(
reason: value.reason,
context: new Set(),
});
const message =
const variable =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `\`${effect.value.identifier.name.value}\` cannot be modified`
: 'This value cannot be modified';
? `\`${effect.value.identifier.name.value}\``
: 'value';
applyEffect(
context,
state,
@@ -1078,11 +1077,11 @@ function applyEffect(
error: CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'This value cannot be modified',
description: reason,
description: `${reason}.`,
}).withDetail({
kind: 'error',
loc: effect.value.loc,
message,
message: `${variable} cannot be modified`,
}),
},
initialized,
@@ -1987,6 +1986,7 @@ function computeSignatureForInstruction(
break;
}
case 'StoreGlobal': {
const variable = `\`${value.name}\``;
effects.push({
kind: 'MutateGlobal',
place: value.value,
@@ -1994,13 +1994,11 @@ function computeSignatureForInstruction(
severity: ErrorSeverity.InvalidReact,
category:
'Cannot reassign variables declared outside of the component/hook',
description:
'Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)',
suggestions: null,
description: `Variable ${variable} is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)`,
}).withDetail({
kind: 'error',
loc: instr.loc,
message: 'Cannot reassign variable',
message: `${variable} cannot be reassigned`,
}),
});
effects.push({kind: 'Assign', from: value.value, into: lvalue});
@@ -2099,7 +2097,6 @@ function computeEffectsForLegacySignature(
? `\`${signature.canonicalName}\` is an impure function. `
: '') +
'Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)',
suggestions: null,
}).withDetail({
kind: 'error',
loc,
@@ -29,15 +29,20 @@ export function validateLocalsNotReassignedAfterRender(fn: HIRFunction): void {
);
if (reassignment !== null) {
const errors = new CompilerError();
const variable =
reassignment.identifier.name != null &&
reassignment.identifier.name.kind === 'named'
? `\`${reassignment.identifier.name.value}\``
: 'variable';
errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot reassign a variable after render completes',
description: `Reassigning ${reassignment.identifier.name != null && reassignment.identifier.name.kind === 'named' ? `variable \`${reassignment.identifier.name.value}\`` : 'a variable'} after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead`,
category: 'Cannot reassign variable after render completes',
description: `Reassigning ${variable} after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.`,
}).withDetail({
kind: 'error',
loc: reassignment.loc,
message: 'Cannot reassign variable after render completes',
message: `Cannot reassign ${variable} after render completes`,
}),
);
throw errors;
@@ -78,16 +83,25 @@ function getContextReassignment(
// if the function or its depends reassign, propagate that fact on the lvalue
if (reassignment !== null) {
if (isAsync || value.loweredFunc.func.async) {
CompilerError.throwInvalidReact({
reason:
'Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead',
description:
reassignment.identifier.name !== null &&
reassignment.identifier.name.kind === 'named'
? `Variable \`${reassignment.identifier.name.value}\` cannot be reassigned after render`
: '',
loc: reassignment.loc,
});
const errors = new CompilerError();
const variable =
reassignment.identifier.name !== null &&
reassignment.identifier.name.kind === 'named'
? `\`${reassignment.identifier.name.value}\``
: 'variable';
errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot reassign variable in async function',
description:
'Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead',
}).withDetail({
kind: 'error',
loc: reassignment.loc,
message: `Cannot reassign ${variable}`,
}),
);
throw errors;
}
reassigningFunctions.set(lvalue.identifier.id, reassignment);
}
@@ -57,22 +57,28 @@ export function validateNoFreezingKnownMutableFunctions(
if (operand.effect === Effect.Freeze) {
const effect = contextMutationEffects.get(operand.identifier.id);
if (effect != null) {
const place = [...effect.places][0];
const variable =
place != null &&
place.identifier.name != null &&
place.identifier.name.kind === 'named'
? `\`${place.identifier.name.value}\``
: 'a local variable';
errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot modify local variables after render completes',
description: `This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead`,
description: `This argument is a function which may reassign or mutate ${variable} after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.`,
})
.withDetail({
kind: 'error',
loc: operand.loc,
message:
'This function may (indirectly) reassign or modify local variables after render',
message: `This function may (indirectly) reassign or modify ${variable} after render`,
})
.withDetail({
kind: 'error',
loc: effect.loc,
message: 'This modifies a local variable',
message: `This modifies ${variable}`,
}),
);
}
@@ -82,7 +82,7 @@ export function validateUseMemo(fn: HIRFunction): Result<void, CompilerError> {
}).withDetail({
kind: 'error',
loc,
message: '',
message: 'Callbacks with parameters are not supported',
}),
);
}
@@ -92,9 +92,9 @@ export function validateUseMemo(fn: HIRFunction): Result<void, CompilerError> {
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category:
'useMemo callbacks may not be async or generator functions',
'useMemo() callbacks may not be async or generator functions',
description:
'useMemo() callbacks are called once and must synchronously return a value',
'useMemo() callbacks are called once and must synchronously return a value.',
suggestions: null,
}).withDetail({
kind: 'error',
@@ -58,7 +58,8 @@ it('logs failed compilation', () => {
expect(event.detail.severity).toEqual('InvalidReact');
//@ts-ignore
const {start, end, identifierName} = event.detail.loc as t.SourceLocation;
const {start, end, identifierName} =
event.detail.primaryLocation() as t.SourceLocation;
expect(start).toEqual({column: 28, index: 28, line: 1});
expect(end).toEqual({column: 33, index: 33, line: 1});
expect(identifierName).toEqual('props');
@@ -16,6 +16,7 @@ function Component(props) {
```
Found 1 error:
Todo: (BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern
error._todo.computed-lval-in-destructure.ts:3:9
@@ -26,8 +27,6 @@ error._todo.computed-lval-in-destructure.ts:3:9
4 |
5 | return x;
6 | }
```
@@ -16,15 +16,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.assign-global-in-component-tag-function.ts:3:4
1 | function Component() {
2 | const Foo = () => {
> 3 | someGlobal = true;
| ^^^^^^^^^^ Cannot reassign variable
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
4 | };
5 | return <Foo />;
6 | }
@@ -19,15 +19,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.assign-global-in-jsx-children.ts:3:4
1 | function Component() {
2 | const foo = () => {
> 3 | someGlobal = true;
| ^^^^^^^^^^ Cannot reassign variable
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
4 | };
5 | // Children are generally access/called during render, so
6 | // modifying a global in a children function is almost
@@ -17,6 +17,7 @@ function Component() {
```
Found 1 error:
Error: Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.assign-global-in-jsx-spread-attribute.ts:4:4
@@ -27,8 +28,6 @@ error.assign-global-in-jsx-spread-attribute.ts:4:4
5 | };
6 | return <div {...foo} />;
7 | }
```
@@ -17,6 +17,7 @@ function Foo(props) {
```
Found 1 error:
Error: React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
$FlowFixMe[react-rule-hook].
@@ -29,8 +30,6 @@ error.bailout-on-flow-suppression.ts:4:2
5 | useX();
6 | return null;
7 | }
```
@@ -20,6 +20,7 @@ function lowercasecomponent() {
```
Found 2 errors:
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
eslint-disable my-app/react-rule.
@@ -33,7 +34,6 @@ error.bailout-on-suppression-of-custom-rule.ts:3:0
5 | 'use forget';
6 | const x = [];
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
eslint-disable-next-line my-app/react-rule.
@@ -46,8 +46,6 @@ error.bailout-on-suppression-of-custom-rule.ts:7:2
8 | return <div>{x}</div>;
9 | }
10 | /* eslint-enable my-app/react-rule */
```
@@ -37,9 +37,10 @@ function Component() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead
This argument is a function which may reassign or mutate a local variable after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.bug-old-inference-false-positive-ref-validation-in-use-effect.ts:20:12
18 | );
@@ -53,7 +54,7 @@ error.bug-old-inference-false-positive-ref-validation-in-use-effect.ts:20:12
> 23 | }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 24 | }, [update]);
| ^^^^ This function may (indirectly) reassign or modify local variables after render
| ^^^^ This function may (indirectly) reassign or modify a local variable after render
25 |
26 | return 'ok';
27 | }
@@ -15,6 +15,7 @@ function Component(props) {
```
Found 1 error:
Invariant: Const declaration cannot be referenced as an expression
error.call-args-destructuring-asignment-complex.ts:3:9
@@ -25,8 +26,6 @@ error.call-args-destructuring-asignment-complex.ts:3:9
4 | return x;
5 | }
6 |
```
@@ -15,6 +15,7 @@ function Foo() {
```
Found 1 error:
Error: Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config
Bar may be a component..
@@ -26,8 +27,6 @@ error.capitalized-function-call-aliased.ts:4:2
| ^^^ Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config
5 | }
6 |
```
@@ -16,6 +16,7 @@ function Component() {
```
Found 1 error:
Error: Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config
SomeFunc may be a component..
@@ -28,8 +29,6 @@ error.capitalized-function-call.ts:3:12
4 |
5 | return x;
6 | }
```
@@ -16,6 +16,7 @@ function Component() {
```
Found 1 error:
Error: Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config
SomeFunc may be a component..
@@ -28,8 +29,6 @@ error.capitalized-method-call.ts:3:12
4 |
5 | return x;
6 | }
```
@@ -33,6 +33,7 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 4 errors:
Error: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
error.capture-ref-for-mutation.ts:12:13
@@ -44,7 +45,6 @@ error.capture-ref-for-mutation.ts:12:13
14 | const moveRight = {
15 | handler: handleKey('right')(),
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.capture-ref-for-mutation.ts:12:13
@@ -56,7 +56,6 @@ error.capture-ref-for-mutation.ts:12:13
14 | const moveRight = {
15 | handler: handleKey('right')(),
Error: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
error.capture-ref-for-mutation.ts:15:13
@@ -68,7 +67,6 @@ error.capture-ref-for-mutation.ts:15:13
17 | return [moveLeft, moveRight];
18 | }
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.capture-ref-for-mutation.ts:15:13
@@ -79,8 +77,6 @@ error.capture-ref-for-mutation.ts:15:13
16 | };
17 | return [moveLeft, moveRight];
18 | }
```
@@ -17,6 +17,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)
error.conditional-hook-unknown-hook-react-namespace.ts:4:8
@@ -27,8 +28,6 @@ error.conditional-hook-unknown-hook-react-namespace.ts:4:8
5 | }
6 | return x;
7 | }
```
@@ -17,6 +17,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)
error.conditional-hooks-as-method-call.ts:4:8
@@ -27,8 +28,6 @@ error.conditional-hooks-as-method-call.ts:4:8
5 | }
6 | return x;
7 | }
```
@@ -29,15 +29,16 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.context-variable-only-chained-assign.ts:10:19
8 | };
9 | const fn2 = () => {
> 10 | const copy2 = (x = 4);
| ^ Cannot reassign variable after render completes
| ^ Cannot reassign `x` after render completes
11 | return [invoke(fn1), copy2, identity(copy2)];
12 | };
13 | return invoke(fn2);
@@ -18,15 +18,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.declare-reassign-variable-in-function-declaration.ts:4:4
2 | let x = null;
3 | function foo() {
> 4 | x = 9;
| ^ Cannot reassign variable after render completes
| ^ Cannot reassign `x` after render completes
5 | }
6 | const y = bar(foo);
7 | return <Child y={y} />;
@@ -23,6 +23,7 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Todo: (BuildHIR::node.lowerReorderableExpression) Expression type `ArrowFunctionExpression` cannot be safely reordered
error.default-param-accesses-local.ts:3:6
@@ -37,8 +38,6 @@ error.default-param-accesses-local.ts:3:6
6 | ) {
7 | return y();
8 | }
```
@@ -20,6 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Todo: [hoisting] EnterSSA: Expected identifier to be defined before being used
Identifier x$1 is undefined.
@@ -32,8 +33,6 @@ error.dont-hoist-inline-reference.ts:3:2
4 | return x;
5 | }
6 |
```
@@ -16,6 +16,7 @@ function useFoo(props) {
```
Found 1 error:
Todo: Encountered conflicting global in generated program
Conflict from local binding __DEV__.
@@ -28,8 +29,6 @@ error.emit-freeze-conflicting-global.ts:3:8
4 | console.log(__DEV__);
5 | return foo(props.x);
6 | }
```
@@ -16,15 +16,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `callback` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `callback` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.function-expression-references-variable-its-assigned-to.ts:3:4
1 | function Component() {
2 | let callback = () => {
> 3 | callback = null;
| ^^^^^^^^ Cannot reassign variable after render completes
| ^^^^^^^^ Cannot reassign `callback` after render completes
4 | };
5 | return <div onClick={callback} />;
6 | }
@@ -25,6 +25,7 @@ function Component(props) {
```
Found 1 error:
Memoization: Compilation skipped because existing memoization could not be preserved
React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
@@ -25,6 +25,7 @@ function Component(props) {
```
Found 1 error:
Memoization: Compilation skipped because existing memoization could not be preserved
React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
@@ -25,6 +25,7 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Todo: Support functions with unreachable code that may contain hoisted declarations
error.hoisting-simple-function-declaration.ts:6:2
@@ -39,8 +40,6 @@ error.hoisting-simple-function-declaration.ts:6:2
9 | }
10 |
11 | export const FIXTURE_ENTRYPOINT = {
```
@@ -30,15 +30,16 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook
Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook.
error.hook-call-freezes-captured-identifier.ts:13:2
11 | });
12 |
> 13 | x.value += count;
| ^ This value cannot be modified
| ^ value cannot be modified
14 | return <Stringify x={x} cb={cb} />;
15 | }
16 |
@@ -30,15 +30,16 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook
Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook.
error.hook-call-freezes-captured-memberexpr.ts:13:2
11 | });
12 |
> 13 | x.value += count;
| ^ This value cannot be modified
| ^ value cannot be modified
14 | return <Stringify x={x} cb={cb} />;
15 | }
16 |
@@ -24,6 +24,7 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 2 errors:
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.hook-property-load-local-hook.ts:7:12
@@ -35,7 +36,6 @@ error.hook-property-load-local-hook.ts:7:12
9 | }
10 |
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.hook-property-load-local-hook.ts:8:9
@@ -46,8 +46,6 @@ error.hook-property-load-local-hook.ts:8:9
9 | }
10 |
11 | export const FIXTURE_ENTRYPOINT = {
```
@@ -21,17 +21,6 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 2 errors:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.hook-ref-value.ts:5:23
3 | function Component(props) {
4 | const ref = useRef();
> 5 | useEffect(() => {}, [ref.current]);
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
6 | }
7 |
8 | export const FIXTURE_ENTRYPOINT = {
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
@@ -44,7 +33,16 @@ error.hook-ref-value.ts:5:23
7 |
8 | export const FIXTURE_ENTRYPOINT = {
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.hook-ref-value.ts:5:23
3 | function Component(props) {
4 | const ref = useRef();
> 5 | useEffect(() => {}, [ref.current]);
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
6 | }
7 |
8 | export const FIXTURE_ENTRYPOINT = {
```
@@ -16,9 +16,10 @@ function component(a, b) {
```
Found 1 error:
Error: useMemo callbacks may not be async or generator functions
useMemo() callbacks are called once and must synchronously return a value
Error: useMemo() callbacks may not be async or generator functions
useMemo() callbacks are called once and must synchronously return a value.
error.invalid-ReactUseMemo-async-callback.ts:2:24
1 | function component(a, b) {
@@ -16,6 +16,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-access-ref-during-render.ts:4:16
@@ -26,8 +27,6 @@ error.invalid-access-ref-during-render.ts:4:16
5 | return value;
6 | }
7 |
```
@@ -20,6 +20,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-aliased-ref-in-callback-invoked-during-render-.ts:9:33
@@ -29,8 +30,6 @@ error.invalid-aliased-ref-in-callback-invoked-during-render-.ts:9:33
| ^^^^^^^^^^^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
10 | }
11 |
```
@@ -16,15 +16,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-array-push-frozen.ts:4:2
2 | const x = [];
3 | <div>{x}</div>;
> 4 | x.push(props.value);
| ^ This value cannot be modified
| ^ value cannot be modified
5 | return x;
6 | }
7 |
@@ -15,6 +15,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-assign-hook-to-local.ts:2:12
@@ -24,8 +25,6 @@ error.invalid-assign-hook-to-local.ts:2:12
3 | const state = x(null);
4 | return state[0];
5 | }
```
@@ -17,15 +17,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-computed-store-to-frozen-value.ts:5:2
3 | // freeze
4 | <div>{x}</div>;
> 5 | x[0] = true;
| ^ This value cannot be modified
| ^ value cannot be modified
6 | return x;
7 | }
8 |
@@ -19,6 +19,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)
error.invalid-conditional-call-aliased-hook-import.ts:6:11
@@ -29,8 +30,6 @@ error.invalid-conditional-call-aliased-hook-import.ts:6:11
7 | }
8 | return data;
9 | }
```
@@ -19,6 +19,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)
error.invalid-conditional-call-aliased-react-hook.ts:6:10
@@ -29,8 +30,6 @@ error.invalid-conditional-call-aliased-react-hook.ts:6:10
7 | }
8 | return s;
9 | }
```
@@ -19,6 +19,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)
error.invalid-conditional-call-non-hook-imported-as-hook.ts:6:11
@@ -29,8 +30,6 @@ error.invalid-conditional-call-non-hook-imported-as-hook.ts:6:11
7 | }
8 | return data;
9 | }
```
@@ -23,6 +23,7 @@ function Component({item, cond}) {
```
Found 2 errors:
Error: Calling setState from useMemo may trigger an infinite loop
Each time the memo callback is evaluated it will change state. This can cause a memoization dependency to change, running the memo function again and causing an infinite loop. Instead of setting state in useMemo(), prefer deriving the value during render. (https://react.dev/reference/react/useState)
@@ -35,6 +36,7 @@ error.invalid-conditional-setState-in-useMemo.ts:7:6
8 | setState(0);
9 | }
10 | }, [cond, key, init]);
Error: Calling setState from useMemo may trigger an infinite loop
Each time the memo callback is evaluated it will change state. This can cause a memoization dependency to change, running the memo function again and causing an infinite loop. Instead of setting state in useMemo(), prefer deriving the value during render. (https://react.dev/reference/react/useState)
@@ -17,15 +17,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-delete-computed-property-of-frozen-value.ts:5:9
3 | // freeze
4 | <div>{x}</div>;
> 5 | delete x[y];
| ^ This value cannot be modified
| ^ value cannot be modified
6 | return x;
7 | }
8 |
@@ -17,15 +17,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-delete-property-of-frozen-value.ts:5:9
3 | // freeze
4 | <div>{x}</div>;
> 5 | delete x.y;
| ^ This value cannot be modified
| ^ value cannot be modified
6 | return x;
7 | }
8 |
@@ -14,14 +14,15 @@ function useFoo(props) {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
Variable `x` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.invalid-destructure-assignment-to-global.ts:2:3
1 | function useFoo(props) {
> 2 | [x] = props;
| ^ Cannot reassign variable
| ^ `x` cannot be reassigned
3 | return {x};
4 | }
5 |
@@ -16,15 +16,16 @@ function Component(props) {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
Variable `b` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.invalid-destructure-to-local-global-variables.ts:3:6
1 | function Component(props) {
2 | let a;
> 3 | [a, b] = props.value;
| ^ Cannot reassign variable
| ^ `b` cannot be reassigned
4 |
5 | return [a, b];
6 | }
@@ -17,6 +17,7 @@ function Component() {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-disallow-mutating-ref-in-render.ts:4:2
@@ -27,8 +28,6 @@ error.invalid-disallow-mutating-ref-in-render.ts:4:2
5 |
6 | return <button ref={ref} />;
7 | }
```
@@ -22,6 +22,7 @@ function Component() {
```
Found 2 errors:
Error: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-disallow-mutating-refs-in-render-transitive.ts:9:2
@@ -33,7 +34,6 @@ error.invalid-disallow-mutating-refs-in-render-transitive.ts:9:2
11 | return <button ref={ref} />;
12 | }
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-disallow-mutating-refs-in-render-transitive.ts:9:2
@@ -44,8 +44,6 @@ error.invalid-disallow-mutating-refs-in-render-transitive.ts:9:2
10 |
11 | return <button ref={ref} />;
12 | }
```
@@ -14,6 +14,7 @@ function Component(props) {
```
Found 1 error:
Error: The 'eval' function is not supported
Eval is an anti-pattern in JavaScript, and the code executed cannot be evaluated by React Compiler.
@@ -25,8 +26,6 @@ error.invalid-eval-unsupported.ts:2:2
3 | return <div />;
4 | }
5 |
```
@@ -19,9 +19,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead
Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead.
error.invalid-function-expression-mutates-immutable-value.ts:5:4
3 | const onChange = e => {
@@ -36,15 +36,16 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
error.invalid-global-reassignment-indirect.ts:9:4
7 |
8 | const setGlobal = () => {
> 9 | someGlobal = true;
| ^^^^^^^^^^ Cannot reassign variable
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
10 | };
11 | const indirectSetGlobal = () => {
12 | setGlobal();
@@ -39,15 +39,16 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Cannot access variable before it is declared
Variable `setState` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time
`setState` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.
error.invalid-hoisting-setstate.ts:19:18
17 | * $2 = Function context=setState
18 | */
> 19 | useEffect(() => setState(2), []);
| ^^^^^^^^ Variable accessed before it is declared
| ^^^^^^^^ `setState` accessed before it is declared
20 |
21 | const [state, setState] = useState(0);
22 | return <Stringify state={state} />;
@@ -56,7 +57,7 @@ error.invalid-hoisting-setstate.ts:21:16
19 | useEffect(() => setState(2), []);
20 |
> 21 | const [state, setState] = useState(0);
| ^^^^^^^^ The variable is declared here
| ^^^^^^^^ `setState` is declared here
22 | return <Stringify state={state} />;
23 | }
24 |
@@ -18,9 +18,10 @@ function useFoo() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead
This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-hook-function-argument-mutates-local-variable.ts:5:10
3 | function useFoo() {
@@ -30,7 +31,7 @@ error.invalid-hook-function-argument-mutates-local-variable.ts:5:10
> 6 | cache.set('key', 'value');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | });
| ^^^^ This function may (indirectly) reassign or modify local variables after render
| ^^^^ This function may (indirectly) reassign or modify `cache` after render
8 | }
9 |
@@ -38,7 +39,7 @@ error.invalid-hook-function-argument-mutates-local-variable.ts:6:4
4 | const cache = new Map();
5 | useHook(() => {
> 6 | cache.set('key', 'value');
| ^^^^^ This modifies a local variable
| ^^^^^ This modifies `cache`
7 | });
8 | }
9 |
@@ -18,6 +18,7 @@ function Component() {
```
Found 3 errors:
Error: Cannot call impure function during render
`Date.now` is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
@@ -30,6 +31,7 @@ error.invalid-impure-functions-in-render.ts:4:15
5 | const now = performance.now();
6 | const rand = Math.random();
7 | return <Foo date={date} now={now} rand={rand} />;
Error: Cannot call impure function during render
`performance.now` is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
@@ -42,6 +44,7 @@ error.invalid-impure-functions-in-render.ts:5:14
6 | const rand = Math.random();
7 | return <Foo date={date} now={now} rand={rand} />;
8 | }
Error: Cannot call impure function during render
`Math.random` is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
@@ -51,9 +51,10 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-jsx-captures-context-variable.ts:22:2
20 | />
@@ -26,15 +26,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-mutate-after-aliased-freeze.ts:13:2
11 | // y is MaybeFrozen at this point, since it may alias to x
12 | // (which is the above line freezes)
> 13 | y.push(props.p2);
| ^ This value cannot be modified
| ^ value cannot be modified
14 |
15 | return <Component x={x} y={y} />;
16 | }
@@ -20,15 +20,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-mutate-after-freeze.ts:7:2
5 |
6 | // x is Frozen at this point
> 7 | x.push(props.p2);
| ^ This value cannot be modified
| ^ value cannot be modified
8 |
9 | return <div>{_}</div>;
10 | }
@@ -25,9 +25,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value returned from 'useContext()' is not allowed.
Modifying a value returned from 'useContext()' is not allowed..
error.invalid-mutate-context-in-callback.ts:12:4
10 | // independently
@@ -15,15 +15,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value returned from 'useContext()' is not allowed.
Modifying a value returned from 'useContext()' is not allowed..
error.invalid-mutate-context.ts:3:2
1 | function Component(props) {
2 | const context = useContext(FooContext);
> 3 | context.value = props.value;
| ^^^^^^^ This value cannot be modified
| ^^^^^^^ value cannot be modified
4 | return context.value;
5 | }
6 |
@@ -26,9 +26,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
error.invalid-mutate-props-in-effect-fixpoint.ts:10:4
8 | let y = x;
@@ -18,15 +18,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
error.invalid-mutate-props-via-for-of-iterator.ts:4:4
2 | const items = [];
3 | for (const x of props.items) {
> 4 | x.modified = true;
| ^ This value cannot be modified
| ^ value cannot be modified
5 | items.push(x);
6 | }
7 | return items;
@@ -17,9 +17,10 @@ function useInvalidMutation(options) {
```
Found 1 error:
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
error.invalid-mutation-in-closure.ts:4:4
2 | function test() {
@@ -20,9 +20,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a variable defined outside a component or hook is not allowed. Consider using an effect
Modifying a variable defined outside a component or hook is not allowed. Consider using an effect.
error.invalid-mutation-of-possible-props-phi-indirect.ts:4:4
2 | let x = cond ? someGlobal : props.foo;
@@ -47,15 +47,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-nested-function-reassign-local-variable-in-effect.ts:7:6
5 | // Create the reassignment function inside another function, then return it
6 | const reassignLocal = newValue => {
> 7 | local = newValue;
| ^^^^^ Cannot reassign variable after render completes
| ^^^^^ Cannot reassign `local` after render completes
8 | };
9 | return reassignLocal;
10 | };
@@ -25,9 +25,10 @@ function SomeComponent() {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed
Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed.
error.invalid-non-imported-reanimated-shared-value-writes.ts:11:22
9 | return (
@@ -19,6 +19,7 @@ function Component(props) {
```
Found 1 error:
Memoization: Compilation skipped because existing memoization could not be preserved
React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items.edges.nodes`, but the source dependencies were [props.items?.edges?.nodes]. Inferred different dependency than source.
@@ -13,6 +13,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-pass-hook-as-call-arg.ts:2:13
@@ -21,8 +22,6 @@ error.invalid-pass-hook-as-call-arg.ts:2:13
| ^^^^^^ Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
3 | }
4 |
```
@@ -13,6 +13,7 @@ function Component(props) {
```
Found 1 error:
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-pass-hook-as-prop.ts:2:21
@@ -21,8 +22,6 @@ error.invalid-pass-hook-as-prop.ts:2:21
| ^^^^^^ Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
3 | }
4 |
```
@@ -18,15 +18,16 @@ function Component() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead
This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-pass-mutable-function-as-prop.ts:7:18
5 | cache.set('key', 'value');
6 | };
> 7 | return <Foo fn={fn} />;
| ^^ This function may (indirectly) reassign or modify local variables after render
| ^^ This function may (indirectly) reassign or modify `cache` after render
8 | }
9 |
@@ -34,7 +35,7 @@ error.invalid-pass-mutable-function-as-prop.ts:5:4
3 | const cache = new Map();
4 | const fn = () => {
> 5 | cache.set('key', 'value');
| ^^^^^ This modifies a local variable
| ^^^^^ This modifies `cache`
6 | };
7 | return <Foo fn={fn} />;
8 | }
@@ -16,6 +16,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-pass-ref-to-function.ts:4:16
@@ -26,8 +27,6 @@ error.invalid-pass-ref-to-function.ts:4:16
5 | return x.current;
6 | }
7 |
```
@@ -19,9 +19,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
error.invalid-prop-mutation-indirect.ts:3:4
1 | function Component(props) {
@@ -17,15 +17,16 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
error.invalid-property-store-to-frozen-value.ts:5:2
3 | // freeze
4 | <div>{x}</div>;
> 5 | x.y = true;
| ^ This value cannot be modified
| ^ value cannot be modified
6 | return x;
7 | }
8 |
@@ -19,9 +19,10 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
error.invalid-props-mutation-in-effect-indirect.ts:3:4
1 | function Component(props) {
@@ -15,6 +15,7 @@ function Component({ref}) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-read-ref-prop-in-render-destructure.ts:3:16
@@ -25,8 +26,6 @@ error.invalid-read-ref-prop-in-render-destructure.ts:3:16
4 | return <div>{value}</div>;
5 | }
6 |
```
@@ -15,6 +15,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-read-ref-prop-in-render-property-load.ts:3:16
@@ -25,8 +26,6 @@ error.invalid-read-ref-prop-in-render-property-load.ts:3:16
4 | return <div>{value}</div>;
5 | }
6 |
```
@@ -14,6 +14,7 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a `const` variable
`x` is declared as const.
@@ -25,8 +26,6 @@ error.invalid-reassign-const.ts:3:2
| ^ Cannot reassign a `const` variable
4 | }
5 |
```
@@ -16,15 +16,16 @@ function useFoo() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-reassign-local-in-hook-return-value.ts:4:4
2 | let x = 0;
3 | return value => {
> 4 | x = value;
| ^ Cannot reassign variable after render completes
| ^ Cannot reassign `x` after render completes
5 | };
6 | }
7 |
@@ -26,20 +26,19 @@ function Component() {
```
Found 1 error:
Error: Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead
Variable `value` cannot be reassigned after render.
Error: Cannot reassign variable in async function
Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead
error.invalid-reassign-local-variable-in-async-callback.ts:8:6
6 | // after render, so this should error regardless of where this ends up
7 | // getting called
> 8 | value = result;
| ^^^^^ Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead
| ^^^^^ Cannot reassign `value`
9 | });
10 | };
11 |
```
@@ -48,15 +48,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-reassign-local-variable-in-effect.ts:7:4
5 |
6 | const reassignLocal = newValue => {
> 7 | local = newValue;
| ^^^^^ Cannot reassign variable after render completes
| ^^^^^ Cannot reassign `local` after render completes
8 | };
9 |
10 | const onMount = newValue => {
@@ -49,15 +49,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-reassign-local-variable-in-hook-argument.ts:8:4
6 |
7 | const reassignLocal = newValue => {
> 8 | local = newValue;
| ^^^^^ Cannot reassign variable after render completes
| ^^^^^ Cannot reassign `local` after render completes
9 | };
10 |
11 | const callback = newValue => {
@@ -42,15 +42,16 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-reassign-local-variable-in-jsx-callback.ts:5:4
3 |
4 | const reassignLocal = newValue => {
> 5 | local = newValue;
| ^^^^^ Cannot reassign variable after render completes
| ^^^^^ Cannot reassign `local` after render completes
6 | };
7 |
8 | const onClick = newValue => {
@@ -19,6 +19,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-ref-in-callback-invoked-during-render.ts:8:33
@@ -28,8 +29,6 @@ error.invalid-ref-in-callback-invoked-during-render.ts:8:33
| ^^^^^^^^^^^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
9 | }
10 |
```
@@ -15,6 +15,7 @@ function Component(props) {
```
Found 1 error:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-ref-value-as-props.ts:4:19
@@ -24,8 +25,6 @@ error.invalid-ref-value-as-props.ts:4:19
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
5 | }
6 |
```
@@ -20,9 +20,10 @@ function useFoo() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead
This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.
error.invalid-return-mutable-function-from-hook.ts:7:9
5 | useHook(); // for inference to kick in
@@ -32,7 +33,7 @@ error.invalid-return-mutable-function-from-hook.ts:7:9
> 8 | cache.set('key', 'value');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 9 | };
| ^^^^ This function may (indirectly) reassign or modify local variables after render
| ^^^^ This function may (indirectly) reassign or modify `cache` after render
10 | }
11 |
@@ -40,7 +41,7 @@ error.invalid-return-mutable-function-from-hook.ts:8:4
6 | const cache = new Map();
7 | return () => {
> 8 | cache.set('key', 'value');
| ^^^^^ This modifies a local variable
| ^^^^^ This modifies `cache`
9 | };
10 | }
11 |
@@ -16,6 +16,7 @@ function Component(props) {
```
Found 2 errors:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-set-and-read-ref-during-render.ts:4:2
@@ -27,7 +28,6 @@ error.invalid-set-and-read-ref-during-render.ts:4:2
6 | }
7 |
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-set-and-read-ref-during-render.ts:5:9
@@ -37,8 +37,6 @@ error.invalid-set-and-read-ref-during-render.ts:5:9
| ^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
6 | }
7 |
```
@@ -16,6 +16,7 @@ function Component(props) {
```
Found 2 errors:
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-set-and-read-ref-nested-property-during-render.ts:4:2
@@ -27,7 +28,6 @@ error.invalid-set-and-read-ref-nested-property-during-render.ts:4:2
6 | }
7 |
Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
error.invalid-set-and-read-ref-nested-property-during-render.ts:5:9
@@ -37,8 +37,6 @@ error.invalid-set-and-read-ref-nested-property-during-render.ts:5:9
| ^^^^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
6 | }
7 |
```
@@ -27,6 +27,7 @@ function useKeyedState({key, init}) {
```
Found 1 error:
Error: Calling setState from useMemo may trigger an infinite loop
Each time the memo callback is evaluated it will change state. This can cause a memoization dependency to change, running the memo function again and causing an infinite loop. Instead of setting state in useMemo(), prefer deriving the value during render. (https://react.dev/reference/react/useState)
@@ -21,6 +21,7 @@ function useKeyedState({key, init}) {
```
Found 2 errors:
Error: Calling setState from useMemo may trigger an infinite loop
Each time the memo callback is evaluated it will change state. This can cause a memoization dependency to change, running the memo function again and causing an infinite loop. Instead of setting state in useMemo(), prefer deriving the value during render. (https://react.dev/reference/react/useState)
@@ -33,6 +34,7 @@ error.invalid-setState-in-useMemo.ts:6:4
7 | setState(init);
8 | }, [key, init]);
9 |
Error: Calling setState from useMemo may trigger an infinite loop
Each time the memo callback is evaluated it will change state. This can cause a memoization dependency to change, running the memo function again and causing an infinite loop. Instead of setting state in useMemo(), prefer deriving the value during render. (https://react.dev/reference/react/useState)
@@ -18,6 +18,7 @@ function lowercasecomponent() {
```
Found 2 errors:
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
eslint-disable react-hooks/rules-of-hooks.
@@ -29,7 +30,6 @@ error.invalid-sketchy-code-use-forget.ts:1:0
3 | 'use forget';
4 | const x = [];
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
eslint-disable-next-line react-hooks/rules-of-hooks.
@@ -42,8 +42,6 @@ error.invalid-sketchy-code-use-forget.ts:5:2
6 | return <div>{x}</div>;
7 | }
8 | /* eslint-enable react-hooks/rules-of-hooks */
```
@@ -14,6 +14,7 @@ function Component(props) {
```
Found 4 errors:
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-ternary-with-hook-values.ts:2:25
@@ -24,7 +25,6 @@ error.invalid-ternary-with-hook-values.ts:2:25
4 | }
5 |
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-ternary-with-hook-values.ts:2:32
@@ -35,7 +35,6 @@ error.invalid-ternary-with-hook-values.ts:2:32
4 | }
5 |
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-ternary-with-hook-values.ts:2:12
@@ -46,7 +45,6 @@ error.invalid-ternary-with-hook-values.ts:2:12
4 | }
5 |
Error: Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
error.invalid-ternary-with-hook-values.ts:3:9
@@ -56,8 +54,6 @@ error.invalid-ternary-with-hook-values.ts:3:9
| ^ Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values
4 | }
5 |
```
@@ -15,6 +15,7 @@ function Component() {
```
Found 1 error:
Error: Invalid type configuration for module
Expected type for object property 'useHookNotTypedAsHook' from module 'ReactCompilerTest' to be a hook based on the property name.
@@ -26,8 +27,6 @@ error.invalid-type-provider-hook-name-not-typed-as-hook-namespace.ts:4:9
| ^^^^^^^^^^^^^^^^^ Invalid type configuration for module
5 | }
6 |
```
@@ -15,6 +15,7 @@ function Component() {
```
Found 1 error:
Error: Invalid type configuration for module
Expected type for object property 'useHookNotTypedAsHook' from module 'ReactCompilerTest' to be a hook based on the property name.
@@ -26,8 +27,6 @@ error.invalid-type-provider-hook-name-not-typed-as-hook.ts:4:9
| ^^^^^^^^^^^^^^^^^^^^^ Invalid type configuration for module
5 | }
6 |
```
@@ -15,6 +15,7 @@ function Component() {
```
Found 1 error:
Error: Invalid type configuration for module
Expected type for `import ... from 'useDefaultExportNotTypedAsHook'` to be a hook based on the module name.
@@ -26,8 +27,6 @@ error.invalid-type-provider-hooklike-module-default-not-hook.ts:4:15
| ^^^ Invalid type configuration for module
5 | }
6 |
```
@@ -15,6 +15,7 @@ function Component() {
```
Found 1 error:
Error: Invalid type configuration for module
Expected type for object property 'useHookNotTypedAsHook' from module 'ReactCompilerTest' to be a hook based on the property name.
@@ -26,8 +27,6 @@ error.invalid-type-provider-nonhook-name-typed-as-hook.ts:4:15
| ^^^^^^^^^^^^^^^^^^^ Invalid type configuration for module
5 | }
6 |
```
@@ -48,11 +48,11 @@ hook useMemoMap<TInput: interface {}, TOutput>(
```
Found 1 error:
Error: Cannot modify local variables after render completes
This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead
This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.
undefined:21:9
19 | map: TInput => TOutput
20 | ): TInput => TOutput {
> 21 | return useMemo(() => {
@@ -88,15 +88,14 @@ undefined:21:9
> 36 | };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 37 | }, [map]);
| ^^^^^^^^^^^^ This function may (indirectly) reassign or modify local variables after render
| ^^^^^^^^^^^^ This function may (indirectly) reassign or modify `cache` after render
38 | }
39 |
undefined:33:8
31 | if (output == null) {
32 | output = map(input);
> 33 | cache.set(input, output);
| ^^^^^ This modifies a local variable
| ^^^^^ This modifies `cache`
34 | }
35 | return output;
36 | };
@@ -37,6 +37,7 @@ function CrimesAgainstReact() {
```
Found 1 error:
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
eslint-disable react-hooks/rules-of-hooks.
@@ -48,8 +49,6 @@ error.invalid-unclosed-eslint-suppression.ts:2:0
3 | function lowercasecomponent() {
4 | 'use forget';
5 | const x = [];
```
@@ -20,6 +20,7 @@ function Component(props) {
```
Found 2 errors:
Error: Calling setState during render may trigger an infinite loop
Calling setState during render will trigger another render, and can lead to infinite loops. (https://react.dev/reference/react/useState)
@@ -32,6 +33,7 @@ error.invalid-unconditional-set-state-in-render.ts:6:2
7 | aliased(2);
8 |
9 | return x;
Error: Calling setState during render may trigger an infinite loop
Calling setState during render will trigger another render, and can lead to infinite loops. (https://react.dev/reference/react/useState)

Some files were not shown because too many files have changed in this diff Show More