Update ValidatePreservedManualMemoization severity to CannotPreserveMemoization
Update ValidatePreservedManualMemoization severity to CannotPreserveMemoization We do need to fix the error location to point to the "callsite" rather than the definition of the useMemo callback, but that aside, even if the error message were perfect, it's not meant to be actionable to the user. So let's change the severity to CannotPreserveMemoization. This preserves the validation, but the eslint plugin won't report it. ghstack-source-id: 722c88922884de05e89030a7b001bd93e0a2a114 Pull Request resolved: https://github.com/facebook/react-forget/pull/2825
Lauren Tan committed
Apr 8, 2024 at 10:55 UTC
0d0f7c2ad178cc546f04bf5b302d0c27609bc3cc
7 files changed
+8
-8
compiler/packages/babel-plugin-react-forget/src/Validation/ValidatePreservedManualMemoization.ts
+1
-1
@@ -439,7 +439,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
439
reason:
440
"This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized",
441
description: null,
442
- severity: ErrorSeverity.InvalidReact,
442
+ severity: ErrorSeverity.CannotPreserveMemoization,
443
loc: typeof instruction.loc !== "symbol" ? instruction.loc : null,
444
suggestions: null,
445
});
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-repro-unmemoized-callback-captured-in-context-variable.expect.md
+1
-1
@@ -53,7 +53,7 @@ export const FIXTURE_ENTRYPOINT = {
53
9 | const a = useHook();
54
10 | // Because b is also part of that same mutable range, it can't be memoized either
55
> 11 | const b = useMemo(() => ({}), []);
56
- | ^^^^^^^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (11:11)
56
+ | ^^^^^^^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (11:11)
57
12 |
58
13 | // Conditional assignment without a subsequent mutation normally doesn't create a mutable
59
14 | // range, but in this case we're reassigning a context variable
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-useCallback-accesses-ref-mutated-later-via-function-preserve-memoization.expect.md
+1
-1
@@ -45,7 +45,7 @@ export const FIXTURE_ENTRYPOINT = {
45
> 10 | ref.current.inner = event.target.value;
46
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47
> 11 | });
48
- | ^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (7:11)
48
+ | ^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (7:11)
49
12 |
50
13 | // The ref is modified later, extending its range and preventing memoization of onChange
51
14 | const reset = () => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-useCallback-set-ref-nested-property-ref-modified-later-preserve-memoization.expect.md
+1
-1
@@ -42,7 +42,7 @@ export const FIXTURE_ENTRYPOINT = {
42
> 10 | ref.current.inner = event.target.value;
43
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
> 11 | });
45
- | ^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (7:11)
45
+ | ^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (7:11)
46
12 |
47
13 | // The ref is modified later, extending its range and preventing memoization of onChange
48
14 | ref.current.inner = null;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.expect.md
+1
-1
@@ -36,7 +36,7 @@ export const FIXTURE_ENTRYPOINT = {
36
> 13 | return identity(val);
37
| ^^^^^^^^^^^^^^^^^^^^^^^^^
38
> 14 | }, [val]);
39
- | ^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:14)
39
+ | ^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:14)
40
15 | }
41
16 |
42
17 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.expect.md
+2
-2
@@ -33,9 +33,9 @@ export const FIXTURE_ENTRYPOINT = {
33
10 |
34
11 | // makeArray() is captured, but depsList contains [props]
35
> 12 | const cb = useCallback(() => [x], [x]);
36
- | ^^^^^^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:12)
36
+ | ^^^^^^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:12)
37
38
-InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:12)
38
+CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (12:12)
39
13 |
40
14 | x = makeArray();
41
15 |
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.expect.md
+1
-1
@@ -31,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
31
11 | x.push(props);
32
12 |
33
> 13 | return useCallback(() => [x], [x]);
34
- | ^^^^^^^^^ InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (13:13)
34
+ | ^^^^^^^^^ CannotPreserveMemoization: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (13:13)
35
14 | }
36
15 |
37
16 | export const FIXTURE_ENTRYPOINT = {