Make Other mutation validation message more generic

The current error message "This mutates a global or a variable after it 

was passed to React" no longer makes sense since we now have more 

specific error messages for different kinds of Effect.Mutate or 

Effect.Stores. This replaces the fallthrough "Other" case with a 

more generic message. It's not perfect, but it's a little more accurate 

than what is currently emitted 

The proper fix might be to treat functions as mutable objects and allow 

the mutation, or special case `Function.displayName`. For now though 

this PR just updates the message in the meantime so it's less 

confusing.
This commit is contained in:
Lauren Tan
2024-02-01 11:02:30 -05:00
parent a0aa66ca8f
commit 7bce302421
2 changed files with 2 additions and 2 deletions
@@ -1506,6 +1506,6 @@ function getWriteErrorReason(abstractValue: AbstractValue): string {
} else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
return "Mutating props or hook arguments is not allowed. Consider using a local variable instead.";
} else {
return "This mutates a global or a variable after it was passed to React, which means that React cannot observe changes to it.";
return "This mutates a variable that React considers immutable.";
}
}
@@ -15,7 +15,7 @@ export function ViewModeSelector(props) {
## Error
```
[ReactForget] InvalidReact: This mutates a global or a variable after it was passed to React, which means that React cannot observe changes to it. (3:3)
[ReactForget] InvalidReact: This mutates a variable that React considers immutable. (3:3)
```