@samitouri / QOS-React-1 / commits / 7bce302421

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.

Lauren Tan committed Feb 1, 2024 at 11:02 UTC 7bce30242137b4668b656feb866184a418cb537a
2 files changed +2 -2
compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
+1 -1
@@ -1506,6 +1506,6 @@ function getWriteErrorReason(abstractValue: AbstractValue): string {
1506 } else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) {
1507 return "Mutating props or hook arguments is not allowed. Consider using a local variable instead.";
1508 } else {
1509 - return "This mutates a global or a variable after it was passed to React, which means that React cannot observe changes to it.";
1509 + return "This mutates a variable that React considers immutable.";
1510 }
1511 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md
+1 -1
@@ -15,7 +15,7 @@ export function ViewModeSelector(props) {
15 ## Error
16
17 ```
18 -[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)
18 +[ReactForget] InvalidReact: This mutates a variable that React considers immutable. (3:3)
19 ```
20
21
\ No newline at end of file