From 7bce30242137b4668b656feb866184a418cb537a Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 1 Feb 2024 11:02:30 -0500 Subject: [PATCH] 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. --- .../src/Inference/InferReferenceEffects.ts | 2 +- .../fixtures/compiler/error.mutate-function-property.expect.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts b/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts index 70c57c908a..79ebcb449c 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts @@ -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."; } } diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md index 863bf529ea..11de342493 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md @@ -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) ``` \ No newline at end of file