Compare commits

..

1 Commits

Author SHA1 Message Date
Joe Savona
2283eb9183 [compiler] Improve more error messages
This PR uses the new diagnostic type for most of the error messages produced in our explicit validation passes (`Validation/` directory). One of the validations produced multiple errors as a hack to showing multiple related locations, which we can now consolidate into a single diagnostic.
2025-07-24 15:38:22 -07:00
323 changed files with 1111 additions and 1012 deletions

View File

@@ -84,9 +84,7 @@ export default function BabelPluginReactCompiler(
}
} catch (e) {
if (e instanceof CompilerError) {
throw new Error(
e.printErrorMessage(pass.file.code, {eslint: false}),
);
throw new Error(e.printErrorMessage(pass.file.code));
}
throw e;
}

View File

@@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
import * as t from '@babel/types';
import {codeFrameColumns} from '@babel/code-frame';
import type {SourceLocation} from './HIR';
import {Err, Ok, Result} from './Utils/Result';
@@ -94,14 +93,6 @@ 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;
@@ -137,7 +128,7 @@ export class CompilerDiagnostic {
return this.options.details.filter(d => d.kind === 'error')[0]?.loc ?? null;
}
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
printErrorMessage(source: string): string {
const buffer = [
printErrorSummary(this.severity, this.category),
'\n\n',
@@ -152,18 +143,28 @@ export class CompilerDiagnostic {
}
let codeFrame: string;
try {
codeFrame = printCodeFrame(source, loc, detail.message);
codeFrame = codeFrameColumns(
source,
{
start: {
line: loc.start.line,
column: loc.start.column + 1,
},
end: {
line: loc.end.line,
column: loc.end.column + 1,
},
},
{
message: detail.message,
},
);
} catch (e) {
codeFrame = detail.message;
}
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(
`\n\n${loc.filename}:${loc.start.line}:${loc.start.column}\n`,
);
buffer.push(codeFrame);
break;
}
@@ -222,7 +223,7 @@ export class CompilerErrorDetail {
return this.loc;
}
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
printErrorMessage(source: string): string {
const buffer = [printErrorSummary(this.severity, this.reason)];
if (this.description != null) {
buffer.push(`\n\n${this.description}.`);
@@ -231,16 +232,28 @@ export class CompilerErrorDetail {
if (loc != null && typeof loc !== 'symbol') {
let codeFrame: string;
try {
codeFrame = printCodeFrame(source, loc, this.reason);
codeFrame = codeFrameColumns(
source,
{
start: {
line: loc.start.line,
column: loc.start.column + 1,
},
end: {
line: loc.end.line,
column: loc.end.column + 1,
},
},
{
message: this.reason,
},
);
} catch (e) {
codeFrame = '';
}
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(
`\n\n${loc.filename}:${loc.start.line}:${loc.start.column}\n`,
);
buffer.push(codeFrame);
buffer.push('\n\n');
}
@@ -359,15 +372,10 @@ export class CompilerError extends Error {
return this.name;
}
printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
if (options.eslint && this.details.length === 1) {
return this.details[0].printErrorMessage(source, options);
}
printErrorMessage(source: string): string {
return (
`Found ${this.details.length} error${this.details.length === 1 ? '' : 's'}:\n\n` +
this.details
.map(detail => detail.printErrorMessage(source, options).trim())
.join('\n\n')
`Found ${this.details.length} error${this.details.length === 1 ? '' : 's'}:\n` +
this.details.map(detail => detail.printErrorMessage(source)).join('\n')
);
}
@@ -430,29 +438,6 @@ export class CompilerError extends Error {
}
}
function printCodeFrame(
source: string,
loc: t.SourceLocation,
message: string,
): string {
return codeFrameColumns(
source,
{
start: {
line: loc.start.line,
column: loc.start.column + 1,
},
end: {
line: loc.end.line,
column: loc.end.column + 1,
},
},
{
message,
},
);
}
function printErrorSummary(severity: ErrorSeverity, message: string): string {
let severityCategory: string;
switch (severity) {

View File

@@ -107,9 +107,10 @@ export function lower(
if (binding.kind !== 'Identifier') {
builder.errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.Invariant,
category: 'Could not find binding',
description: `[BuildHIR] Could not find binding for param \`${param.node.name}\`.`,
description: `[BuildHIR] Could not find binding for param \`${param.node.name}\``,
severity: ErrorSeverity.Invariant,
suggestions: null,
}).withDetail({
kind: 'error',
loc: param.node.loc ?? null,
@@ -171,9 +172,10 @@ export function lower(
} else {
builder.errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.Todo,
category: `Handle ${param.node.type} parameters`,
description: `[BuildHIR] Add support for ${param.node.type} parameters.`,
description: `[BuildHIR] Add support for ${param.node.type} parameters`,
severity: ErrorSeverity.Todo,
suggestions: null,
}).withDetail({
kind: 'error',
loc: param.node.loc ?? null,
@@ -203,7 +205,8 @@ 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}\`.`,
description: `Expected function body to be an expression or a block statement, got \`${body.type}\``,
suggestions: null,
}).withDetail({
kind: 'error',
loc: body.node.loc ?? null,

View File

@@ -995,13 +995,13 @@ export function printAliasingEffect(effect: AliasingEffect): string {
return `${effect.kind} ${printPlaceForAliasEffect(effect.value)}`;
}
case 'MutateFrozen': {
return `MutateFrozen ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.category)}`;
return `MutateFrozen ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.reason)}`;
}
case 'MutateGlobal': {
return `MutateGlobal ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.category)}`;
return `MutateGlobal ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.reason)}`;
}
case 'Impure': {
return `Impure ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.category)}`;
return `Impure ${printPlaceForAliasEffect(effect.place)} reason=${JSON.stringify(effect.error.reason)}`;
}
case 'Render': {
return `Render ${printPlaceForAliasEffect(effect.place)}`;

View File

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {CompilerDiagnostic} from '../CompilerError';
import {CompilerErrorDetailOptions} from '../CompilerError';
import {
FunctionExpression,
GeneratedSource,
@@ -133,19 +133,19 @@ export type AliasingEffect =
/**
* Mutation of a value known to be immutable
*/
| {kind: 'MutateFrozen'; place: Place; error: CompilerDiagnostic}
| {kind: 'MutateFrozen'; place: Place; error: CompilerErrorDetailOptions}
/**
* Mutation of a global
*/
| {
kind: 'MutateGlobal';
place: Place;
error: CompilerDiagnostic;
error: CompilerErrorDetailOptions;
}
/**
* Indicates a side-effect that is not safe during render
*/
| {kind: 'Impure'; place: Place; error: CompilerDiagnostic}
| {kind: 'Impure'; place: Place; error: CompilerErrorDetailOptions}
/**
* Indicates that a given place is accessed during render. Used to distingush
* hook arguments that are known to be called immediately vs those used for
@@ -211,9 +211,9 @@ export function hashEffect(effect: AliasingEffect): string {
effect.kind,
effect.place.identifier.id,
effect.error.severity,
effect.error.category,
effect.error.reason,
effect.error.description,
printSourceLocation(effect.error.primaryLocation() ?? GeneratedSource),
printSourceLocation(effect.error.loc ?? GeneratedSource),
].join(':');
}
case 'Mutate':

View File

@@ -326,26 +326,26 @@ function isEffectSafeOutsideRender(effect: FunctionEffect): boolean {
export function getWriteErrorReason(abstractValue: AbstractValue): string {
if (abstractValue.reason.has(ValueReason.Global)) {
return 'Modifying a variable defined outside a component or hook is not allowed. Consider using an effect';
return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect';
} else if (abstractValue.reason.has(ValueReason.JsxCaptured)) {
return 'Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX';
return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX';
} else if (abstractValue.reason.has(ValueReason.Context)) {
return `Modifying a value returned from 'useContext()' is not allowed.`;
return `Mutating a value returned from 'useContext()', which should not be mutated`;
} else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) {
return 'Modifying a value returned from a function whose return value should not be mutated';
return 'Mutating a value returned from a function whose return value should not be mutated';
} else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
return 'Modifying component props or hook arguments is not allowed. Consider using a local variable instead';
return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead';
} else if (abstractValue.reason.has(ValueReason.State)) {
return "Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead";
return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
} else if (abstractValue.reason.has(ValueReason.ReducerState)) {
return "Modifying a value returned from 'useReducer()', which should not be modified directly. Use the dispatch function to update instead";
return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
} else if (abstractValue.reason.has(ValueReason.Effect)) {
return 'Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect()';
return 'Updating a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the mutation before calling useEffect()';
} else if (abstractValue.reason.has(ValueReason.HookCaptured)) {
return 'Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook';
return 'Updating a value previously passed as an argument to a hook is not allowed. Consider moving the mutation before calling the hook';
} else if (abstractValue.reason.has(ValueReason.HookReturn)) {
return 'Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed';
return 'Updating a value returned from a hook is not allowed. Consider moving the mutation into the hook where the value is constructed';
} else {
return 'This modifies a variable that React considers immutable';
return 'This mutates a variable that React considers immutable';
}
}

View File

@@ -6,7 +6,6 @@
*/
import {
CompilerDiagnostic,
CompilerError,
Effect,
ErrorSeverity,
@@ -447,23 +446,20 @@ function applySignature(
reason: value.reason,
context: new Set(),
});
const variable =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `\`${effect.value.identifier.name.value}\``
: 'value';
effects.push({
kind: 'MutateFrozen',
place: effect.value,
error: CompilerDiagnostic.create({
error: {
severity: ErrorSeverity.InvalidReact,
category: 'This value cannot be modified',
description: `${reason}.`,
}).withDetail({
kind: 'error',
reason,
description:
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `Found mutation of \`${effect.value.identifier.name.value}\``
: null,
loc: effect.value.loc,
message: `${variable} cannot be modified`,
}),
suggestions: null,
},
});
}
}
@@ -1017,31 +1013,33 @@ function applyEffect(
effect.value.identifier.declarationId,
)
) {
const variable =
const description =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `\`${effect.value.identifier.name.value}\``
? `Variable \`${effect.value.identifier.name.value}\` is accessed before it is declared`
: 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: `${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 ?? 'variable'} accessed before it is declared`,
});
applyEffect(
context,
state,
{
kind: 'MutateFrozen',
place: effect.value,
error: {
severity: ErrorSeverity.InvalidReact,
reason: `This variable is accessed before it is declared, which may prevent it from updating as the assigned value changes over time`,
description,
loc: hoistedAccess.loc,
suggestions: null,
},
},
initialized,
effects,
);
}
diagnostic.withDetail({
kind: 'error',
loc: effect.value.loc,
message: `${variable ?? 'variable'} is declared here`,
});
applyEffect(
context,
@@ -1049,7 +1047,13 @@ function applyEffect(
{
kind: 'MutateFrozen',
place: effect.value,
error: diagnostic,
error: {
severity: ErrorSeverity.InvalidReact,
reason: `This variable is accessed before it is declared, which prevents the earlier access from updating when this value changes over time`,
description,
loc: effect.value.loc,
suggestions: null,
},
},
initialized,
effects,
@@ -1060,11 +1064,11 @@ function applyEffect(
reason: value.reason,
context: new Set(),
});
const variable =
const description =
effect.value.identifier.name !== null &&
effect.value.identifier.name.kind === 'named'
? `\`${effect.value.identifier.name.value}\``
: 'value';
? `Found mutation of \`${effect.value.identifier.name.value}\``
: null;
applyEffect(
context,
state,
@@ -1074,15 +1078,13 @@ function applyEffect(
? 'MutateFrozen'
: 'MutateGlobal',
place: effect.value,
error: CompilerDiagnostic.create({
error: {
severity: ErrorSeverity.InvalidReact,
category: 'This value cannot be modified',
description: `${reason}.`,
}).withDetail({
kind: 'error',
reason,
description,
loc: effect.value.loc,
message: `${variable} cannot be modified`,
}),
suggestions: null,
},
},
initialized,
effects,
@@ -2001,20 +2003,16 @@ function computeSignatureForInstruction(
break;
}
case 'StoreGlobal': {
const variable = `\`${value.name}\``;
effects.push({
kind: 'MutateGlobal',
place: value.value,
error: CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category:
'Cannot reassign variables declared outside of the component/hook',
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',
error: {
reason:
'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)',
loc: instr.loc,
message: `${variable} cannot be reassigned`,
}),
suggestions: null,
severity: ErrorSeverity.InvalidReact,
},
});
effects.push({kind: 'Assign', from: value.value, into: lvalue});
break;
@@ -2104,19 +2102,17 @@ function computeEffectsForLegacySignature(
effects.push({
kind: 'Impure',
place: receiver,
error: CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot call impure function during render',
error: {
reason:
'Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)',
description:
(signature.canonicalName != null
? `\`${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)',
}).withDetail({
kind: 'error',
signature.canonicalName != null
? `\`${signature.canonicalName}\` is an impure function whose results may change on every call`
: null,
severity: ErrorSeverity.InvalidReact,
loc,
message: 'Cannot call impure function',
}),
suggestions: null,
},
});
}
const stores: Array<Place> = [];

View File

@@ -195,7 +195,7 @@ export function inferMutationAliasingRanges(
effect.kind === 'MutateGlobal' ||
effect.kind === 'Impure'
) {
errors.pushDiagnostic(effect.error);
errors.push(effect.error);
functionEffects.push(effect);
} else if (effect.kind === 'Render') {
renders.push({index: index++, place: effect.place});
@@ -549,7 +549,7 @@ function appendFunctionErrors(errors: CompilerError, fn: HIRFunction): void {
case 'Impure':
case 'MutateFrozen':
case 'MutateGlobal': {
errors.pushDiagnostic(effect.error);
errors.push(effect.error);
break;
}
}

View File

@@ -29,20 +29,15 @@ 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 variable after render completes',
description: `Reassigning ${variable} after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.`,
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`,
}).withDetail({
kind: 'error',
loc: reassignment.loc,
message: `Cannot reassign ${variable} after render completes`,
message: 'Cannot reassign variable after render completes',
}),
);
throw errors;
@@ -83,25 +78,16 @@ function getContextReassignment(
// if the function or its depends reassign, propagate that fact on the lvalue
if (reassignment !== null) {
if (isAsync || value.loweredFunc.func.async) {
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;
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,
});
}
reassigningFunctions.set(lvalue.identifier.id, reassignment);
}

View File

@@ -57,28 +57,22 @@ 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 ${variable} 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 local variables 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 ${variable} after render`,
message:
'This function may (indirectly) reassign or modify local variables after render',
})
.withDetail({
kind: 'error',
loc: effect.loc,
message: `This modifies ${variable}`,
message: 'This modifies a local variable',
}),
);
}

View File

@@ -5,11 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {
CompilerDiagnostic,
CompilerError,
ErrorSeverity,
} from '../CompilerError';
import {CompilerError, ErrorSeverity} from '../CompilerError';
import {
DeclarationId,
Effect,
@@ -279,37 +275,27 @@ function validateInferredDep(
errorDiagnostic = merge(errorDiagnostic ?? compareResult, compareResult);
}
}
errorState.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.CannotPreserveMemoization,
category:
'Compilation skipped because existing memoization could not be preserved',
description: [
'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. ',
DEBUG ||
// If the dependency is a named variable then we can report it. Otherwise only print in debug mode
(dep.identifier.name != null && dep.identifier.name.kind === 'named')
? `The inferred dependency was \`${prettyPrintScopeDependency(
dep,
)}\`, but the source dependencies were [${validDepsInMemoBlock
.map(dep => printManualMemoDependency(dep, true))
.join(', ')}]. ${
errorDiagnostic
? getCompareDependencyResultDescription(errorDiagnostic)
: 'Inferred dependency not present in source'
}.`
: '',
]
.join('')
.trim(),
suggestions: null,
}).withDetail({
kind: 'error',
loc: memoLocation,
message: 'Could not preserve existing manual memoization',
}),
);
errorState.push({
severity: ErrorSeverity.CannotPreserveMemoization,
reason:
'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',
description:
DEBUG ||
// If the dependency is a named variable then we can report it. Otherwise only print in debug mode
(dep.identifier.name != null && dep.identifier.name.kind === 'named')
? `The inferred dependency was \`${prettyPrintScopeDependency(
dep,
)}\`, but the source dependencies were [${validDepsInMemoBlock
.map(dep => printManualMemoDependency(dep, true))
.join(', ')}]. ${
errorDiagnostic
? getCompareDependencyResultDescription(errorDiagnostic)
: 'Inferred dependency not present in source'
}`
: null,
loc: memoLocation,
suggestions: null,
});
}
class Visitor extends ReactiveFunctionVisitor<VisitorState> {
@@ -533,21 +519,14 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
!this.scopes.has(identifier.scope.id) &&
!this.prunedScopes.has(identifier.scope.id)
) {
state.errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.CannotPreserveMemoization,
category:
'Compilation skipped because existing memoization could not be preserved',
description: [
'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. ',
'This dependency may be mutated later, which could cause the value to change unexpectedly.',
].join(''),
}).withDetail({
kind: 'error',
loc,
message: 'This dependency may be modified later',
}),
);
state.errors.push({
reason:
'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly',
description: null,
severity: ErrorSeverity.CannotPreserveMemoization,
loc,
suggestions: null,
});
}
}
}
@@ -581,25 +560,16 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
for (const identifier of decls) {
if (isUnmemoized(identifier, this.scopes)) {
state.errors.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.CannotPreserveMemoization,
category:
'Compilation skipped because existing memoization could not be preserved',
description: [
'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output. ',
DEBUG
? `${printIdentifier(identifier)} was not memoized.`
: '',
]
.join('')
.trim(),
}).withDetail({
kind: 'error',
loc,
message: 'Could not preserve existing memoization',
}),
);
state.errors.push({
reason:
'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.',
description: DEBUG
? `${printIdentifier(identifier)} was not memoized`
: null,
severity: ErrorSeverity.CannotPreserveMemoization,
loc,
suggestions: null,
});
}
}
}

View File

@@ -5,11 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {
CompilerDiagnostic,
CompilerError,
ErrorSeverity,
} from '../CompilerError';
import {CompilerError, ErrorSeverity} from '../CompilerError';
import {HIRFunction, IdentifierId, SourceLocation} from '../HIR';
import {Result} from '../Utils/Result';
@@ -63,23 +59,20 @@ export function validateStaticComponents(
value.tag.identifier.id,
);
if (location != null) {
error.pushDiagnostic(
CompilerDiagnostic.create({
severity: ErrorSeverity.InvalidReact,
category: 'Cannot create components during render',
description: `Components created during render will reset their state each time they are created. Declare components outside of render. `,
})
.withDetail({
kind: 'error',
loc: value.tag.loc,
message: 'This component is created during render',
})
.withDetail({
kind: 'error',
loc: location,
message: 'The component is created during render here',
}),
);
error.push({
reason: `Components created during render will reset their state each time they are created. Declare components outside of render. `,
severity: ErrorSeverity.InvalidReact,
loc: value.tag.loc,
description: null,
suggestions: null,
});
error.push({
reason: `The component may be created during render`,
severity: ErrorSeverity.InvalidReact,
loc: location,
description: null,
suggestions: null,
});
}
}
}

View File

@@ -82,7 +82,7 @@ export function validateUseMemo(fn: HIRFunction): Result<void, CompilerError> {
}).withDetail({
kind: 'error',
loc,
message: 'Callbacks with parameters are not supported',
message: '',
}),
);
}
@@ -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',

View File

@@ -58,8 +58,7 @@ it('logs failed compilation', () => {
expect(event.detail.severity).toEqual('InvalidReact');
//@ts-ignore
const {start, end, identifierName} =
event.detail.primaryLocation() as t.SourceLocation;
const {start, end, identifierName} = event.detail.loc 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');

View File

@@ -16,7 +16,6 @@ function Component(props) {
```
Found 1 error:
Todo: (BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern
error._todo.computed-lval-in-destructure.ts:3:9
@@ -27,6 +26,8 @@ error._todo.computed-lval-in-destructure.ts:3:9
4 |
5 | return x;
6 | }
```

View File

@@ -16,19 +16,18 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
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: 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-component-tag-function.ts:3:4
1 | function Component() {
2 | const Foo = () => {
> 3 | someGlobal = true;
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
| ^^^^^^^^^^ 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)
4 | };
5 | return <Foo />;
6 | }
```

View File

@@ -19,19 +19,18 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
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: 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-children.ts:3:4
1 | function Component() {
2 | const foo = () => {
> 3 | someGlobal = true;
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
| ^^^^^^^^^^ 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)
4 | };
5 | // Children are generally access/called during render, so
6 | // modifying a global in a children function is almost
```

View File

@@ -17,7 +17,6 @@ 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
@@ -28,6 +27,8 @@ error.assign-global-in-jsx-spread-attribute.ts:4:4
5 | };
6 | return <div {...foo} />;
7 | }
```

View File

@@ -17,7 +17,6 @@ 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].
@@ -30,6 +29,8 @@ error.bailout-on-flow-suppression.ts:4:2
5 | useX();
6 | return null;
7 | }
```

View File

@@ -20,7 +20,6 @@ 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.
@@ -34,6 +33,7 @@ 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,6 +46,8 @@ error.bailout-on-suppression-of-custom-rule.ts:7:2
8 | return <div>{x}</div>;
9 | }
10 | /* eslint-enable my-app/react-rule */
```

View File

@@ -37,10 +37,9 @@ function Component() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
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.
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
error.bug-old-inference-false-positive-ref-validation-in-use-effect.ts:20:12
18 | );
@@ -54,7 +53,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 a local variable after render
| ^^^^ This function may (indirectly) reassign or modify local variables after render
25 |
26 | return 'ok';
27 | }

View File

@@ -15,7 +15,6 @@ function Component(props) {
```
Found 1 error:
Invariant: Const declaration cannot be referenced as an expression
error.call-args-destructuring-asignment-complex.ts:3:9
@@ -26,6 +25,8 @@ error.call-args-destructuring-asignment-complex.ts:3:9
4 | return x;
5 | }
6 |
```

View File

@@ -15,7 +15,6 @@ 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..
@@ -27,6 +26,8 @@ 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 |
```

View File

@@ -16,7 +16,6 @@ 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..
@@ -29,6 +28,8 @@ error.capitalized-function-call.ts:3:12
4 |
5 | return x;
6 | }
```

View File

@@ -16,7 +16,6 @@ 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..
@@ -29,6 +28,8 @@ error.capitalized-method-call.ts:3:12
4 |
5 | return x;
6 | }
```

View File

@@ -33,7 +33,6 @@ 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
@@ -45,6 +44,7 @@ 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,6 +56,7 @@ 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
@@ -67,6 +68,7 @@ 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
@@ -77,6 +79,8 @@ error.capture-ref-for-mutation.ts:15:13
16 | };
17 | return [moveLeft, moveRight];
18 | }
```

View File

@@ -17,7 +17,6 @@ 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
@@ -28,6 +27,8 @@ error.conditional-hook-unknown-hook-react-namespace.ts:4:8
5 | }
6 | return x;
7 | }
```

View File

@@ -17,7 +17,6 @@ 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
@@ -28,6 +27,8 @@ error.conditional-hooks-as-method-call.ts:4:8
5 | }
6 | return x;
7 | }
```

View File

@@ -29,16 +29,15 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `x` after render completes
| ^ Cannot reassign variable after render completes
11 | return [invoke(fn1), copy2, identity(copy2)];
12 | };
13 | return invoke(fn2);

View File

@@ -18,16 +18,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `x` after render completes
| ^ Cannot reassign variable after render completes
5 | }
6 | const y = bar(foo);
7 | return <Child y={y} />;

View File

@@ -23,7 +23,6 @@ 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
@@ -38,6 +37,8 @@ error.default-param-accesses-local.ts:3:6
6 | ) {
7 | return y();
8 | }
```

View File

@@ -20,7 +20,6 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Todo: [hoisting] EnterSSA: Expected identifier to be defined before being used
Identifier x$1 is undefined.
@@ -33,6 +32,8 @@ error.dont-hoist-inline-reference.ts:3:2
4 | return x;
5 | }
6 |
```

View File

@@ -16,7 +16,6 @@ function useFoo(props) {
```
Found 1 error:
Todo: Encountered conflicting global in generated program
Conflict from local binding __DEV__.
@@ -29,6 +28,8 @@ error.emit-freeze-conflicting-global.ts:3:8
4 | console.log(__DEV__);
5 | return foo(props.x);
6 | }
```

View File

@@ -16,16 +16,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `callback` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `callback` after render completes
| ^^^^^^^^ Cannot reassign variable after render completes
4 | };
5 | return <div onClick={callback} />;
6 | }

View File

@@ -25,10 +25,9 @@ function Component(props) {
```
Found 1 error:
Memoization: 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
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.
The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
error.hoist-optional-member-expression-with-conditional-optional.ts:4:23
2 | import {ValidateMemoization} from 'shared-runtime';
@@ -48,10 +47,12 @@ error.hoist-optional-member-expression-with-conditional-optional.ts:4:23
> 10 | return x;
| ^^^^^^^^^^^^^^^^^
> 11 | }, [props?.items, props.cond]);
| ^^^^ Could not preserve existing manual memoization
| ^^^^ 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
12 | return (
13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
14 | );
```

View File

@@ -25,10 +25,9 @@ function Component(props) {
```
Found 1 error:
Memoization: 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
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.
The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
error.hoist-optional-member-expression-with-conditional.ts:4:23
2 | import {ValidateMemoization} from 'shared-runtime';
@@ -48,10 +47,12 @@ error.hoist-optional-member-expression-with-conditional.ts:4:23
> 10 | return x;
| ^^^^^^^^^^^^^^^^^
> 11 | }, [props?.items, props.cond]);
| ^^^^ Could not preserve existing manual memoization
| ^^^^ 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
12 | return (
13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
14 | );
```

View File

@@ -25,7 +25,6 @@ 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
@@ -40,6 +39,8 @@ error.hoisting-simple-function-declaration.ts:6:2
9 | }
10 |
11 | export const FIXTURE_ENTRYPOINT = {
```

View File

@@ -30,19 +30,18 @@ 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.
Error: Updating a value previously passed as an argument to a hook is not allowed. Consider moving the mutation before calling the hook
error.hook-call-freezes-captured-identifier.ts:13:2
11 | });
12 |
> 13 | x.value += count;
| ^ value cannot be modified
| ^ Updating a value previously passed as an argument to a hook is not allowed. Consider moving the mutation before calling the hook
14 | return <Stringify x={x} cb={cb} />;
15 | }
16 |
```

View File

@@ -30,19 +30,18 @@ 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.
Error: Updating a value previously passed as an argument to a hook is not allowed. Consider moving the mutation before calling the hook
error.hook-call-freezes-captured-memberexpr.ts:13:2
11 | });
12 |
> 13 | x.value += count;
| ^ value cannot be modified
| ^ Updating a value previously passed as an argument to a hook is not allowed. Consider moving the mutation before calling the hook
14 | return <Stringify x={x} cb={cb} />;
15 | }
16 |
```

View File

@@ -24,7 +24,6 @@ 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
@@ -36,6 +35,7 @@ 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,6 +46,8 @@ error.hook-property-load-local-hook.ts:8:9
9 | }
10 |
11 | export const FIXTURE_ENTRYPOINT = {
```

View File

@@ -21,6 +21,17 @@ 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)
@@ -33,16 +44,7 @@ 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 = {
```

View File

@@ -16,10 +16,9 @@ function component(a, b) {
```
Found 1 error:
Error: useMemo callbacks may not be async or generator functions
Error: useMemo() callbacks may not be async or generator functions
useMemo() callbacks are called once and must synchronously return a value.
useMemo() callbacks are called once and must synchronously return a value
error.invalid-ReactUseMemo-async-callback.ts:2:24
1 | function component(a, b) {

View File

@@ -16,7 +16,6 @@ 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
@@ -27,6 +26,8 @@ error.invalid-access-ref-during-render.ts:4:16
5 | return value;
6 | }
7 |
```

View File

@@ -20,7 +20,6 @@ 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
@@ -30,6 +29,8 @@ 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 |
```

View File

@@ -16,19 +16,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-array-push-frozen.ts:4:2
2 | const x = [];
3 | <div>{x}</div>;
> 4 | x.push(props.value);
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
5 | return x;
6 | }
7 |
```

View File

@@ -15,7 +15,6 @@ 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
@@ -25,6 +24,8 @@ error.invalid-assign-hook-to-local.ts:2:12
3 | const state = x(null);
4 | return state[0];
5 | }
```

View File

@@ -17,19 +17,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-computed-store-to-frozen-value.ts:5:2
3 | // freeze
4 | <div>{x}</div>;
> 5 | x[0] = true;
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
6 | return x;
7 | }
8 |
```

View File

@@ -19,7 +19,6 @@ 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
@@ -30,6 +29,8 @@ error.invalid-conditional-call-aliased-hook-import.ts:6:11
7 | }
8 | return data;
9 | }
```

View File

@@ -19,7 +19,6 @@ 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
@@ -30,6 +29,8 @@ error.invalid-conditional-call-aliased-react-hook.ts:6:10
7 | }
8 | return s;
9 | }
```

View File

@@ -19,7 +19,6 @@ 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
@@ -30,6 +29,8 @@ error.invalid-conditional-call-non-hook-imported-as-hook.ts:6:11
7 | }
8 | return data;
9 | }
```

View File

@@ -23,7 +23,6 @@ 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)
@@ -36,7 +35,6 @@ 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)

View File

@@ -17,19 +17,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-delete-computed-property-of-frozen-value.ts:5:9
3 | // freeze
4 | <div>{x}</div>;
> 5 | delete x[y];
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
6 | return x;
7 | }
8 |
```

View File

@@ -17,19 +17,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-delete-property-of-frozen-value.ts:5:9
3 | // freeze
4 | <div>{x}</div>;
> 5 | delete x.y;
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
6 | return x;
7 | }
8 |
```

View File

@@ -14,18 +14,17 @@ function useFoo(props) {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
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: 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.invalid-destructure-assignment-to-global.ts:2:3
1 | function useFoo(props) {
> 2 | [x] = props;
| ^ `x` cannot be reassigned
| ^ 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)
3 | return {x};
4 | }
5 |
```

View File

@@ -16,19 +16,18 @@ function Component(props) {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
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: 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.invalid-destructure-to-local-global-variables.ts:3:6
1 | function Component(props) {
2 | let a;
> 3 | [a, b] = props.value;
| ^ `b` cannot be reassigned
| ^ 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)
4 |
5 | return [a, b];
6 | }
```

View File

@@ -17,7 +17,6 @@ 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
@@ -28,6 +27,8 @@ error.invalid-disallow-mutating-ref-in-render.ts:4:2
5 |
6 | return <button ref={ref} />;
7 | }
```

View File

@@ -22,7 +22,6 @@ 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
@@ -34,6 +33,7 @@ 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,6 +44,8 @@ error.invalid-disallow-mutating-refs-in-render-transitive.ts:9:2
10 |
11 | return <button ref={ref} />;
12 | }
```

View File

@@ -14,7 +14,6 @@ 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.
@@ -26,6 +25,8 @@ error.invalid-eval-unsupported.ts:2:2
3 | return <div />;
4 | }
5 |
```

View File

@@ -19,19 +19,20 @@ function Component(props) {
```
Found 1 error:
Error: Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead
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.
Found mutation of `x`.
error.invalid-function-expression-mutates-immutable-value.ts:5:4
3 | const onChange = e => {
4 | // INVALID! should use copy-on-write and pass the new value
> 5 | x.value = e.target.value;
| ^ `x` cannot be modified
| ^ Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead
6 | setX(x);
7 | };
8 | return <input value={x.value} onChange={onChange} />;
```

View File

@@ -36,19 +36,18 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Cannot reassign variables declared outside of the component/hook
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: 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.invalid-global-reassignment-indirect.ts:9:4
7 |
8 | const setGlobal = () => {
> 9 | someGlobal = true;
| ^^^^^^^^^^ `someGlobal` cannot be reassigned
| ^^^^^^^^^^ 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)
10 | };
11 | const indirectSetGlobal = () => {
12 | setGlobal();
```

View File

@@ -38,29 +38,35 @@ export const FIXTURE_ENTRYPOINT = {
## Error
```
Found 1 error:
Found 2 errors:
Error: This variable is accessed before it is declared, which may prevent it from updating as the assigned value changes over time
Error: Cannot access variable before it is declared
`setState` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.
Variable `setState` is accessed before it is declared.
error.invalid-hoisting-setstate.ts:19:18
17 | * $2 = Function context=setState
18 | */
> 19 | useEffect(() => setState(2), []);
| ^^^^^^^^ `setState` accessed before it is declared
| ^^^^^^^^ This variable is accessed before it is declared, which may prevent it from updating as the assigned value changes over time
20 |
21 | const [state, setState] = useState(0);
22 | return <Stringify state={state} />;
Error: This variable is accessed before it is declared, which prevents the earlier access from updating when this value changes over time
Variable `setState` is accessed before it is declared.
error.invalid-hoisting-setstate.ts:21:16
19 | useEffect(() => setState(2), []);
20 |
> 21 | const [state, setState] = useState(0);
| ^^^^^^^^ `setState` is declared here
| ^^^^^^^^ This variable is accessed before it is declared, which prevents the earlier access from updating when this value changes over time
22 | return <Stringify state={state} />;
23 | }
24 |
```

View File

@@ -18,10 +18,9 @@ function useFoo() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
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.
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
error.invalid-hook-function-argument-mutates-local-variable.ts:5:10
3 | function useFoo() {
@@ -31,7 +30,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 `cache` after render
| ^^^^ This function may (indirectly) reassign or modify local variables after render
8 | }
9 |
@@ -39,7 +38,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 `cache`
| ^^^^^ This modifies a local variable
7 | });
8 | }
9 |

View File

@@ -18,45 +18,48 @@ function Component() {
```
Found 3 errors:
Error: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
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)
`Date.now` is an impure function whose results may change on every call.
error.invalid-impure-functions-in-render.ts:4:15
2 |
3 | function Component() {
> 4 | const date = Date.now();
| ^^^^^^^^^^ Cannot call impure function
| ^^^^^^^^^^ Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
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)
Error: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
`performance.now` is an impure function whose results may change on every call.
error.invalid-impure-functions-in-render.ts:5:14
3 | function Component() {
4 | const date = Date.now();
> 5 | const now = performance.now();
| ^^^^^^^^^^^^^^^^^ Cannot call impure function
| ^^^^^^^^^^^^^^^^^ Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
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)
Error: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
`Math.random` is an impure function whose results may change on every call.
error.invalid-impure-functions-in-render.ts:6:15
4 | const date = Date.now();
5 | const now = performance.now();
> 6 | const rand = Math.random();
| ^^^^^^^^^^^^^ Cannot call impure function
| ^^^^^^^^^^^^^ Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)
7 | return <Foo date={date} now={now} rand={rand} />;
8 | }
9 |
```

View File

@@ -51,19 +51,20 @@ export const FIXTURE_ENTRYPOINT = {
```
Found 1 error:
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
Error: This value cannot be modified
Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX.
Found mutation of `i`.
error.invalid-jsx-captures-context-variable.ts:22:2
20 | />
21 | );
> 22 | i = i + 1;
| ^ `i` cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
23 | items.push(
24 | <Stringify
25 | key={i}
```

View File

@@ -26,19 +26,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation 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);
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
14 |
15 | return <Component x={x} y={y} />;
16 | }
```

View File

@@ -20,19 +20,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-mutate-after-freeze.ts:7:2
5 |
6 | // x is Frozen at this point
> 7 | x.push(props.p2);
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
8 |
9 | return <div>{_}</div>;
10 | }
```

View File

@@ -25,19 +25,20 @@ function Component(props) {
```
Found 1 error:
Error: Mutating a value returned from 'useContext()', which should not be mutated
Error: This value cannot be modified
Modifying a value returned from 'useContext()' is not allowed..
Found mutation of `FooContext`.
error.invalid-mutate-context-in-callback.ts:12:4
10 | // independently
11 | const onClick = () => {
> 12 | FooContext.current = true;
| ^^^^^^^^^^ `FooContext` cannot be modified
| ^^^^^^^^^^ Mutating a value returned from 'useContext()', which should not be mutated
13 | };
14 | return <div onClick={onClick} />;
15 | }
```

View File

@@ -15,19 +15,18 @@ function Component(props) {
```
Found 1 error:
Error: This value cannot be modified
Modifying a value returned from 'useContext()' is not allowed..
Error: Mutating a value returned from 'useContext()', which should not be mutated
error.invalid-mutate-context.ts:3:2
1 | function Component(props) {
2 | const context = useContext(FooContext);
> 3 | context.value = props.value;
| ^^^^^^^ value cannot be modified
| ^^^^^^^ Mutating a value returned from 'useContext()', which should not be mutated
4 | return context.value;
5 | }
6 |
```

View File

@@ -26,19 +26,20 @@ function Component(props) {
```
Found 1 error:
Error: Mutating component props or hook arguments is not allowed. Consider using a local variable instead
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
Found mutation of `y`.
error.invalid-mutate-props-in-effect-fixpoint.ts:10:4
8 | let y = x;
9 | let mutateProps = () => {
> 10 | y.foo = true;
| ^ `y` cannot be modified
| ^ Mutating component props or hook arguments is not allowed. Consider using a local variable instead
11 | };
12 | let mutatePropsIndirect = () => {
13 | mutateProps();
```

View File

@@ -18,19 +18,18 @@ 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.
Error: Mutating 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;
| ^ value cannot be modified
| ^ Mutating component props or hook arguments is not allowed. Consider using a local variable instead
5 | items.push(x);
6 | }
7 | return items;
```

View File

@@ -17,19 +17,20 @@ function useInvalidMutation(options) {
```
Found 1 error:
Error: Mutating component props or hook arguments is not allowed. Consider using a local variable instead
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
Found mutation of `options`.
error.invalid-mutation-in-closure.ts:4:4
2 | function test() {
3 | foo(options.foo); // error should not point on this line
> 4 | options.foo = 'bar';
| ^^^^^^^ `options` cannot be modified
| ^^^^^^^ Mutating component props or hook arguments is not allowed. Consider using a local variable instead
5 | }
6 | return test;
7 | }
```

View File

@@ -20,19 +20,20 @@ function Component(props) {
```
Found 1 error:
Error: Writing to a variable defined outside a component or hook is not allowed. Consider using an effect
Error: This value cannot be modified
Modifying a variable defined outside a component or hook is not allowed. Consider using an effect.
Found mutation of `x`.
error.invalid-mutation-of-possible-props-phi-indirect.ts:4:4
2 | let x = cond ? someGlobal : props.foo;
3 | const mutatePhiThatCouldBeProps = () => {
> 4 | x.y = true;
| ^ `x` cannot be modified
| ^ Writing to a variable defined outside a component or hook is not allowed. Consider using an effect
5 | };
6 | const indirectMutateProps = () => {
7 | mutatePhiThatCouldBeProps();
```

View File

@@ -47,16 +47,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `local` after render completes
| ^^^^^ Cannot reassign variable after render completes
8 | };
9 | return reassignLocal;
10 | };

View File

@@ -25,19 +25,20 @@ function SomeComponent() {
```
Found 1 error:
Error: Updating a value returned from a hook is not allowed. Consider moving the mutation into the hook where the value is constructed
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.
Found mutation of `sharedVal`.
error.invalid-non-imported-reanimated-shared-value-writes.ts:11:22
9 | return (
10 | <Button
> 11 | onPress={() => (sharedVal.value = Math.random())}
| ^^^^^^^^^ `sharedVal` cannot be modified
| ^^^^^^^^^ Updating a value returned from a hook is not allowed. Consider moving the mutation into the hook where the value is constructed
12 | title="Randomize"
13 | />
14 | );
```

View File

@@ -19,10 +19,9 @@ function Component(props) {
```
Found 1 error:
Memoization: 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
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.
The inferred dependency was `props.items.edges.nodes`, but the source dependencies were [props.items?.edges?.nodes]. Inferred different dependency than source.
error.invalid-optional-member-expression-as-memo-dep-non-optional-in-body.ts:3:23
1 | // @validatePreserveExistingMemoizationGuarantees
@@ -36,10 +35,12 @@ error.invalid-optional-member-expression-as-memo-dep-non-optional-in-body.ts:3:2
> 6 | // deps are optional
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | }, [props.items?.edges?.nodes]);
| ^^^^ Could not preserve existing manual memoization
| ^^^^ 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
8 | return <Foo data={data} />;
9 | }
10 |
```

View File

@@ -13,7 +13,6 @@ 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
@@ -22,6 +21,8 @@ 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 |
```

View File

@@ -13,7 +13,6 @@ 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
@@ -22,6 +21,8 @@ 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 |
```

View File

@@ -18,16 +18,15 @@ function Component() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
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.
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
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 `cache` after render
| ^^ This function may (indirectly) reassign or modify local variables after render
8 | }
9 |
@@ -35,7 +34,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 `cache`
| ^^^^^ This modifies a local variable
6 | };
7 | return <Foo fn={fn} />;
8 | }

View File

@@ -16,7 +16,6 @@ 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
@@ -27,6 +26,8 @@ error.invalid-pass-ref-to-function.ts:4:16
5 | return x.current;
6 | }
7 |
```

View File

@@ -19,19 +19,20 @@ function Component(props) {
```
Found 1 error:
Error: Mutating component props or hook arguments is not allowed. Consider using a local variable instead
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
Found mutation of `props`.
error.invalid-prop-mutation-indirect.ts:3:4
1 | function Component(props) {
2 | const f = () => {
> 3 | props.value = true;
| ^^^^^ `props` cannot be modified
| ^^^^^ Mutating component props or hook arguments is not allowed. Consider using a local variable instead
4 | };
5 | const g = () => {
6 | f();
```

View File

@@ -17,19 +17,18 @@ 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.
Error: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
error.invalid-property-store-to-frozen-value.ts:5:2
3 | // freeze
4 | <div>{x}</div>;
> 5 | x.y = true;
| ^ value cannot be modified
| ^ Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX
6 | return x;
7 | }
8 |
```

View File

@@ -19,19 +19,20 @@ function Component(props) {
```
Found 1 error:
Error: Mutating component props or hook arguments is not allowed. Consider using a local variable instead
Error: This value cannot be modified
Modifying component props or hook arguments is not allowed. Consider using a local variable instead.
Found mutation of `props`.
error.invalid-props-mutation-in-effect-indirect.ts:3:4
1 | function Component(props) {
2 | const mutateProps = () => {
> 3 | props.value = true;
| ^^^^^ `props` cannot be modified
| ^^^^^ Mutating component props or hook arguments is not allowed. Consider using a local variable instead
4 | };
5 | const indirectMutateProps = () => {
6 | mutateProps();
```

View File

@@ -15,7 +15,6 @@ 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
@@ -26,6 +25,8 @@ error.invalid-read-ref-prop-in-render-destructure.ts:3:16
4 | return <div>{value}</div>;
5 | }
6 |
```

View File

@@ -15,7 +15,6 @@ 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
@@ -26,6 +25,8 @@ error.invalid-read-ref-prop-in-render-property-load.ts:3:16
4 | return <div>{value}</div>;
5 | }
6 |
```

View File

@@ -14,7 +14,6 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a `const` variable
`x` is declared as const.
@@ -26,6 +25,8 @@ error.invalid-reassign-const.ts:3:2
| ^ Cannot reassign a `const` variable
4 | }
5 |
```

View File

@@ -16,16 +16,15 @@ function useFoo() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `x` after render completes
| ^ Cannot reassign variable after render completes
5 | };
6 | }
7 |

View File

@@ -26,19 +26,20 @@ function Component() {
```
Found 1 error:
Error: Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead
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
Variable `value` cannot be reassigned after render.
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;
| ^^^^^ Cannot reassign `value`
| ^^^^^ Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead
9 | });
10 | };
11 |
```

View File

@@ -48,16 +48,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `local` after render completes
| ^^^^^ Cannot reassign variable after render completes
8 | };
9 |
10 | const onMount = newValue => {

View File

@@ -49,16 +49,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `local` after render completes
| ^^^^^ Cannot reassign variable after render completes
9 | };
10 |
11 | const callback = newValue => {

View File

@@ -42,16 +42,15 @@ function Component() {
```
Found 1 error:
Error: Cannot reassign a variable after render completes
Error: Cannot reassign variable after render completes
Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.
Reassigning variable `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 `local` after render completes
| ^^^^^ Cannot reassign variable after render completes
6 | };
7 |
8 | const onClick = newValue => {

View File

@@ -19,7 +19,6 @@ 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
@@ -29,6 +28,8 @@ 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 |
```

View File

@@ -15,7 +15,6 @@ 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
@@ -25,6 +24,8 @@ 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 |
```

View File

@@ -20,10 +20,9 @@ function useFoo() {
```
Found 1 error:
Error: Cannot modify local variables after render completes
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.
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
error.invalid-return-mutable-function-from-hook.ts:7:9
5 | useHook(); // for inference to kick in
@@ -33,7 +32,7 @@ error.invalid-return-mutable-function-from-hook.ts:7:9
> 8 | cache.set('key', 'value');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 9 | };
| ^^^^ This function may (indirectly) reassign or modify `cache` after render
| ^^^^ This function may (indirectly) reassign or modify local variables after render
10 | }
11 |
@@ -41,7 +40,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 `cache`
| ^^^^^ This modifies a local variable
9 | };
10 | }
11 |

View File

@@ -16,7 +16,6 @@ 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
@@ -28,6 +27,7 @@ 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,6 +37,8 @@ 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 |
```

View File

@@ -16,7 +16,6 @@ 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
@@ -28,6 +27,7 @@ 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,6 +37,8 @@ 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 |
```

View File

@@ -27,7 +27,6 @@ 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)

View File

@@ -21,7 +21,6 @@ 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)
@@ -34,7 +33,6 @@ 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)

View File

@@ -18,7 +18,6 @@ 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.
@@ -30,6 +29,7 @@ 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,6 +42,8 @@ error.invalid-sketchy-code-use-forget.ts:5:2
6 | return <div>{x}</div>;
7 | }
8 | /* eslint-enable react-hooks/rules-of-hooks */
```

View File

@@ -14,7 +14,6 @@ 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
@@ -25,6 +24,7 @@ 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,6 +35,7 @@ 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
@@ -45,6 +46,7 @@ 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
@@ -54,6 +56,8 @@ 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 |
```

View File

@@ -15,7 +15,6 @@ 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.
@@ -27,6 +26,8 @@ error.invalid-type-provider-hook-name-not-typed-as-hook-namespace.ts:4:9
| ^^^^^^^^^^^^^^^^^ Invalid type configuration for module
5 | }
6 |
```

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