Skip to content

Commit b82b774

Browse files
committed
[compiler] Validate against setState in all effect types
1 parent 96c61b7 commit b82b774

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInPassiveEffects.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import {
1111
IdentifierId,
1212
isSetStateType,
1313
isUseEffectHookType,
14+
isUseInsertionEffectHookType,
15+
isUseLayoutEffectHookType,
1416
Place,
1517
} from '../HIR';
1618
import {eachInstructionValueOperand} from '../HIR/visitors';
1719
import {Result} from '../Utils/Result';
1820

1921
/**
20-
* Validates against calling setState in the body of a *passive* effect (useEffect),
22+
* Validates against calling setState in the body of an effect (useEffect and friends),
2123
* while allowing calling setState in callbacks scheduled by the effect.
2224
*
2325
* Calling setState during execution of a useEffect triggers a re-render, which is
@@ -79,7 +81,11 @@ export function validateNoSetStateInPassiveEffects(
7981
instr.value.kind === 'MethodCall'
8082
? instr.value.receiver
8183
: instr.value.callee;
82-
if (isUseEffectHookType(callee.identifier)) {
84+
if (
85+
isUseEffectHookType(callee.identifier) ||
86+
isUseLayoutEffectHookType(callee.identifier) ||
87+
isUseInsertionEffectHookType(callee.identifier)
88+
) {
8389
const arg = instr.value.args[0];
8490
if (arg !== undefined && arg.kind === 'Identifier') {
8591
const setState = setStateFunctions.get(arg.identifier.id);

0 commit comments

Comments
 (0)