ValidateNoSetStateInEffects.ts — react Source File
Architecture documentation for ValidateNoSetStateInEffects.ts, a typescript file in the react codebase. 17 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 71d73648_b3a1_c2f2_a010_106a2a2c80f6["ValidateNoSetStateInEffects.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> e96f281e_f381_272d_2359_3e6a091c9a1d 0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042["CompilerDiagnostic"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> e51fd0d2_bb38_cc97_7763_efe37f300a47 a2b91621_58d3_1d04_4663_00cd808f1034["ErrorCategory"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> a2b91621_58d3_1d04_4663_00cd808f1034 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 0423f759_97e0_9101_4634_ed555abc5ca9 2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 2f3caf55_cc64_415c_55dd_9771ba7dc210 10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 10043bf1_f7ee_9ed9_307a_fe3edfd02b09 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> b2fc2985_a7ba_9865_c2a3_2a7531f27d44 5d62162e_5fa5_1488_29bf_5150b4be53a0["ControlDominators.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 5d62162e_5fa5_1488_29bf_5150b4be53a0 1c6dc7ec_72e1_b907_d23f_94b6a80c2a2d["createControlDominators"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 1c6dc7ec_72e1_b907_d23f_94b6a80c2a2d f041318d_301f_daad_4198_91d141b3039d["InferReactiveScopeVariables.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> f041318d_301f_daad_4198_91d141b3039d 11746e9a_2fdf_98bb_bb3c_a63d8b200df2["isMutable"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 11746e9a_2fdf_98bb_bb3c_a63d8b200df2 494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 494e3425_0b47_293a_1ea4_d4670b0fc0e7 7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"] 71d73648_b3a1_c2f2_a010_106a2a2c80f6 --> 7aace723_0ee1_cff5_b263_aec8e06dd79e style 71d73648_b3a1_c2f2_a010_106a2a2c80f6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
CompilerDiagnostic,
CompilerError,
ErrorCategory,
} from '../CompilerError';
import {
Environment,
HIRFunction,
IdentifierId,
isSetStateType,
isUseEffectHookType,
isUseEffectEventType,
isUseInsertionEffectHookType,
isUseLayoutEffectHookType,
isUseRefType,
isRefValueType,
Place,
Effect,
BlockId,
} from '../HIR';
import {
eachInstructionLValue,
eachInstructionValueOperand,
} from '../HIR/visitors';
import {createControlDominators} from '../Inference/ControlDominators';
import {isMutable} from '../ReactiveScopes/InferReactiveScopeVariables';
import {Result} from '../Utils/Result';
import {assertExhaustive, Iterable_some} from '../Utils/utils';
/**
* Validates against calling setState in the body of an effect (useEffect and friends),
* while allowing calling setState in callbacks scheduled by the effect.
*
* Calling setState during execution of a useEffect triggers a re-render, which is
* often bad for performance and frequently has more efficient and straightforward
* alternatives. See https://react.dev/learn/you-might-not-need-an-effect for examples.
*/
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,
);
}
// ... (288 more lines)
Domain
Subdomains
Dependencies
Source
Frequently Asked Questions
What does ValidateNoSetStateInEffects.ts do?
ValidateNoSetStateInEffects.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ValidateNoSetStateInEffects.ts?
ValidateNoSetStateInEffects.ts defines 2 function(s): getSetStateCall, validateNoSetStateInEffects.
What does ValidateNoSetStateInEffects.ts depend on?
ValidateNoSetStateInEffects.ts imports 17 module(s): CompilerDiagnostic, CompilerError, CompilerError.ts, ControlDominators.ts, ErrorCategory, InferReactiveScopeVariables.ts, Iterable_some, Result, and 9 more.
What files import ValidateNoSetStateInEffects.ts?
ValidateNoSetStateInEffects.ts is imported by 1 file(s): Pipeline.ts.
Where is ValidateNoSetStateInEffects.ts in the architecture?
ValidateNoSetStateInEffects.ts is located at compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/Validation).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free