validateNoSetStateInEffects() — react Function Reference
Architecture documentation for the validateNoSetStateInEffects() function in ValidateNoSetStateInEffects.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 9122e965_d8f6_df86_dd39_3a5721b58d49["validateNoSetStateInEffects()"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6["ValidateNoSetStateInEffects.ts"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|defined in| 71d73648_b3a1_c2f2_a010_106a2a2c80f6 c3bc3875_256f_8f5e_7800_2f9c5bae65eb["runWithEnvironment()"] c3bc3875_256f_8f5e_7800_2f9c5bae65eb -->|calls| 9122e965_d8f6_df86_dd39_3a5721b58d49 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44 3b48551f_7fdf_a2e3_1a73_61107c6532fd["getSetStateCall()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| 3b48551f_7fdf_a2e3_1a73_61107c6532fd 02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69 ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf 1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab 531eb985_e192_f9a2_2d7b_5deeb85ba95c["asResult()"] 9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| 531eb985_e192_f9a2_2d7b_5deeb85ba95c style 9122e965_d8f6_df86_dd39_3a5721b58d49 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts lines 45–186
export function validateNoSetStateInEffects(
fn: HIRFunction,
env: Environment,
): Result<void, CompilerError> {
const setStateFunctions: Map<IdentifierId, Place> = new Map();
const errors = new CompilerError();
for (const [, block] of fn.body.blocks) {
for (const instr of block.instructions) {
switch (instr.value.kind) {
case 'LoadLocal': {
if (setStateFunctions.has(instr.value.place.identifier.id)) {
setStateFunctions.set(
instr.lvalue.identifier.id,
instr.value.place,
);
}
break;
}
case 'StoreLocal': {
if (setStateFunctions.has(instr.value.value.identifier.id)) {
setStateFunctions.set(
instr.value.lvalue.place.identifier.id,
instr.value.value,
);
setStateFunctions.set(
instr.lvalue.identifier.id,
instr.value.value,
);
}
break;
}
case 'FunctionExpression': {
if (
// faster-path to check if the function expression references a setState
[...eachInstructionValueOperand(instr.value)].some(
operand =>
isSetStateType(operand.identifier) ||
setStateFunctions.has(operand.identifier.id),
)
) {
const callee = getSetStateCall(
instr.value.loweredFunc.func,
setStateFunctions,
env,
);
if (callee !== null) {
setStateFunctions.set(instr.lvalue.identifier.id, callee);
}
}
break;
}
case 'MethodCall':
case 'CallExpression': {
const callee =
instr.value.kind === 'MethodCall'
? instr.value.property
: instr.value.callee;
if (isUseEffectEventType(callee.identifier)) {
const arg = instr.value.args[0];
if (arg !== undefined && arg.kind === 'Identifier') {
const setState = setStateFunctions.get(arg.identifier.id);
if (setState !== undefined) {
/**
* This effect event function calls setState synchonously,
* treat it as a setState function for transitive tracking
*/
setStateFunctions.set(instr.lvalue.identifier.id, setState);
}
}
} else if (
isUseEffectHookType(callee.identifier) ||
isUseLayoutEffectHookType(callee.identifier) ||
isUseInsertionEffectHookType(callee.identifier)
) {
const arg = instr.value.args[0];
if (arg !== undefined && arg.kind === 'Identifier') {
const setState = setStateFunctions.get(arg.identifier.id);
if (setState !== undefined) {
const enableVerbose =
env.config.enableVerboseNoSetStateInEffect;
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does validateNoSetStateInEffects() do?
validateNoSetStateInEffects() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts.
Where is validateNoSetStateInEffects() defined?
validateNoSetStateInEffects() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts at line 45.
What does validateNoSetStateInEffects() call?
validateNoSetStateInEffects() calls 6 function(s): asResult, create, eachInstructionValueOperand, getSetStateCall, pushDiagnostic, withDetails.
What calls validateNoSetStateInEffects()?
validateNoSetStateInEffects() 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