mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
InferReferenceEffects: distinguish conditional mutations in HIR
In InferReferenceEffects, locations that are ConditionallyMutate are either recorded as a Mutate or Read, which means we lose the distinction btw conditional/unconditional mutation in later passes. This PR changes to remember that these places were conditionally mutable, used in later analysis.
This commit is contained in:
@@ -878,16 +878,11 @@ export function isMutableEffect(
|
||||
switch (effect) {
|
||||
case Effect.Capture:
|
||||
case Effect.Store:
|
||||
case Effect.ConditionallyMutate:
|
||||
case Effect.Mutate: {
|
||||
return true;
|
||||
}
|
||||
case Effect.ConditionallyMutate: {
|
||||
// All conditional mutations should be resolved into some other effect after InferReferenceEffects
|
||||
CompilerError.invariant(
|
||||
"Unexpected conditional mutation effect",
|
||||
location
|
||||
);
|
||||
}
|
||||
|
||||
case Effect.Unknown: {
|
||||
CompilerError.invariant("Unexpected unknown effect", location);
|
||||
}
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ class InferenceState {
|
||||
valueKind === ValueKind.Mutable ||
|
||||
valueKind === ValueKind.Context
|
||||
) {
|
||||
effect = Effect.Mutate;
|
||||
effect = Effect.ConditionallyMutate;
|
||||
} else {
|
||||
effect = Effect.Read;
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ function Component(props) {
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate $22[6:8]:TObject<BuiltInUseRefId> (3:3)
|
||||
[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate? $22[6:8]:TObject<BuiltInUseRefId> (3:3)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user