validateNoImpureFunctionsInRender() — react Function Reference
Architecture documentation for the validateNoImpureFunctionsInRender() function in ValidateNoImpureFunctionsInRender.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 78fc714f_8b9c_e011_f056_3f5bb4bf6be4["validateNoImpureFunctionsInRender()"] 350d48bf_14c4_ad84_872f_09fa76881478["ValidateNoImpureFunctionsInRender.ts"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|defined in| 350d48bf_14c4_ad84_872f_09fa76881478 c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 d2c89465_144e_76da_505e_4a2de182f6f4["getFunctionCallSignature()"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|calls| d2c89465_144e_76da_505e_4a2de182f6f4 02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69 ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf 1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab 531eb985_e192_f9a2_2d7b_5deeb85ba95c["asResult()"] 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 -->|calls| 531eb985_e192_f9a2_2d7b_5deeb85ba95c style 78fc714f_8b9c_e011_f056_3f5bb4bf6be4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoImpureFunctionsInRender.ts lines 23–59
export function validateNoImpureFunctionsInRender(
fn: HIRFunction,
): Result<void, CompilerError> {
const errors = new CompilerError();
for (const [, block] of fn.body.blocks) {
for (const instr of block.instructions) {
const value = instr.value;
if (value.kind === 'MethodCall' || value.kind == 'CallExpression') {
const callee =
value.kind === 'MethodCall' ? value.property : value.callee;
const signature = getFunctionCallSignature(
fn.env,
callee.identifier.type,
);
if (signature != null && signature.impure === true) {
errors.pushDiagnostic(
CompilerDiagnostic.create({
category: ErrorCategory.Purity,
reason: 'Cannot call impure function during render',
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)',
suggestions: null,
}).withDetails({
kind: 'error',
loc: callee.loc,
message: 'Cannot call impure function',
}),
);
}
}
}
}
return errors.asResult();
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does validateNoImpureFunctionsInRender() do?
validateNoImpureFunctionsInRender() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoImpureFunctionsInRender.ts.
Where is validateNoImpureFunctionsInRender() defined?
validateNoImpureFunctionsInRender() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoImpureFunctionsInRender.ts at line 23.
What does validateNoImpureFunctionsInRender() call?
validateNoImpureFunctionsInRender() calls 5 function(s): asResult, create, getFunctionCallSignature, pushDiagnostic, withDetails.
What calls validateNoImpureFunctionsInRender()?
validateNoImpureFunctionsInRender() is called by 1 function(s): runWithEnvironment.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free