File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
compiler/packages/babel-plugin-react-compiler/src/Validation Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,15 @@ import {
11
11
IdentifierId ,
12
12
isSetStateType ,
13
13
isUseEffectHookType ,
14
+ isUseInsertionEffectHookType ,
15
+ isUseLayoutEffectHookType ,
14
16
Place ,
15
17
} from '../HIR' ;
16
18
import { eachInstructionValueOperand } from '../HIR/visitors' ;
17
19
import { Result } from '../Utils/Result' ;
18
20
19
21
/**
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 ),
21
23
* while allowing calling setState in callbacks scheduled by the effect.
22
24
*
23
25
* Calling setState during execution of a useEffect triggers a re-render, which is
@@ -79,7 +81,11 @@ export function validateNoSetStateInPassiveEffects(
79
81
instr . value . kind === 'MethodCall'
80
82
? instr . value . receiver
81
83
: instr . value . callee ;
82
- if ( isUseEffectHookType ( callee . identifier ) ) {
84
+ if (
85
+ isUseEffectHookType ( callee . identifier ) ||
86
+ isUseLayoutEffectHookType ( callee . identifier ) ||
87
+ isUseInsertionEffectHookType ( callee . identifier )
88
+ ) {
83
89
const arg = instr . value . args [ 0 ] ;
84
90
if ( arg !== undefined && arg . kind === 'Identifier' ) {
85
91
const setState = setStateFunctions . get ( arg . identifier . id ) ;
You can’t perform that action at this time.
0 commit comments