mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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.";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user