@samitouri / QOS-React-2 / commits / 73d7e816b7

[compiler] ValidatePreservedManualMemoization reports detailed errors

This pass didn't previously report the precise difference btw inferred/manual dependencies unless a debug flag was set. But the error message is really good (nice job mofeiz): the only catch is that in theory the inferred dep could be a temporary that can't trivially be reported to the user. But the messages are really useful for quickly verifying why the compiler couldn't preserve memoization. So here we switch to outputting a detailed message about the discrepancy btw inferred/manual deps so long as the inferred dep root is a named variable. I also slightly adjusted the message to handle the case where there is no diagnostic, which can occur if there were no manual deps but the compiler inferred a dependency. ghstack-source-id: 534f6f1fec0855e05e85077eba050eb2ba254ef8 Pull Request resolved: https://github.com/facebook/react/pull/33095

Joe Savona committed May 3, 2025 at 09:09 UTC 73d7e816b7746c700ab843964aaf11c17351fac1
23 files changed +42 -39
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts
+18 -15
@@ -141,14 +141,14 @@ function getCompareDependencyResultDescription(
141 ): string {
142 switch (result) {
143 case CompareDependencyResult.Ok:
144 - return 'dependencies equal';
144 + return 'Dependencies equal';
145 case CompareDependencyResult.RootDifference:
146 case CompareDependencyResult.PathDifference:
147 - return 'inferred different dependency than source';
147 + return 'Inferred different dependency than source';
148 case CompareDependencyResult.RefAccessDifference:
149 - return 'differences in ref.current access';
149 + return 'Differences in ref.current access';
150 case CompareDependencyResult.Subpath:
151 - return 'inferred less specific property than source';
151 + return 'Inferred less specific property than source';
152 }
153 }
154
@@ -279,17 +279,20 @@ function validateInferredDep(
279 severity: ErrorSeverity.CannotPreserveMemoization,
280 reason:
281 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected',
282 - description: DEBUG
283 - ? `The inferred dependency was \`${prettyPrintScopeDependency(
284 - dep,
285 - )}\`, but the source dependencies were [${validDepsInMemoBlock
286 - .map(dep => printManualMemoDependency(dep, true))
287 - .join(', ')}]. Detail: ${
288 - errorDiagnostic
289 - ? getCompareDependencyResultDescription(errorDiagnostic)
290 - : 'none'
291 - }`
292 - : null,
282 + description:
283 + DEBUG ||
284 + // If the dependency is a named variable then we can report it. Otherwise only print in debug mode
285 + (dep.identifier.name != null && dep.identifier.name.kind === 'named')
286 + ? `The inferred dependency was \`${prettyPrintScopeDependency(
287 + dep,
288 + )}\`, but the source dependencies were [${validDepsInMemoBlock
289 + .map(dep => printManualMemoDependency(dep, true))
290 + .join(', ')}]. ${
291 + errorDiagnostic
292 + ? getCompareDependencyResultDescription(errorDiagnostic)
293 + : 'Inferred dependency not present in source'
294 + }`
295 + : null,
296 loc: memoLocation,
297 suggestions: null,
298 });
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hoist-optional-member-expression-with-conditional-optional.expect.md
+1 -1
@@ -41,7 +41,7 @@ function Component(props) {
41 > 10 | return x;
42 | ^^^^^^^^^^^^^^^^^
43 > 11 | }, [props?.items, props.cond]);
44 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (4:11)
44 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source (4:11)
45 12 | return (
46 13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
47 14 | );
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hoist-optional-member-expression-with-conditional.expect.md
+1 -1
@@ -41,7 +41,7 @@ function Component(props) {
41 > 10 | return x;
42 | ^^^^^^^^^^^^^^^^^
43 > 11 | }, [props?.items, props.cond]);
44 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (4:11)
44 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source (4:11)
45 12 | return (
46 13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
47 14 | );
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-optional-member-expression-as-memo-dep-non-optional-in-body.expect.md
+1 -1
@@ -29,7 +29,7 @@ function Component(props) {
29 > 6 | // deps are optional
30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 > 7 | }, [props.items?.edges?.nodes]);
32 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (3:7)
32 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items.edges.nodes`, but the source dependencies were [props.items?.edges?.nodes]. Inferred different dependency than source (3:7)
33 8 | return <Foo data={data} />;
34 9 | }
35 10 |
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.ref-like-name-not-Ref.expect.md
+1 -1
@@ -38,7 +38,7 @@ export const FIXTURE_ENTRYPOINT = {
38 > 12 | Ref.current?.click();
39 | ^^^^^^^^^^^^^^^^^^^^^^^^^
40 > 13 | }, []);
41 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (11:13)
41 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `Ref.current`, but the source dependencies were []. Inferred dependency not present in source (11:13)
42 14 |
43 15 | return <button onClick={onClick} />;
44 16 | }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.ref-like-name-not-a-ref.expect.md
+1 -1
@@ -38,7 +38,7 @@ export const FIXTURE_ENTRYPOINT = {
38 > 12 | notaref.current?.click();
39 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40 > 13 | }, []);
41 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (11:13)
41 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `notaref.current`, but the source dependencies were []. Inferred dependency not present in source (11:13)
42 14 |
43 15 | return <button onClick={onClick} />;
44 16 | }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.expect.md
+1 -1
@@ -41,7 +41,7 @@ export const FIXTURE_ENTRYPOINT = {
41 > 10 | }
42 | ^^^^^^^^^^^^^^^^
43 > 11 | }, [propA, propB.x.y]);
44 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:11)
44 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA, propB.x.y]. Inferred less specific property than source (5:11)
45 12 | }
46 13 |
47 14 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.expect.md
+2 -2
@@ -48,9 +48,9 @@ export const FIXTURE_ENTRYPOINT = {
48 > 13 | }
49 | ^^^^^^^^^^^^^^^^^
50 > 14 | }, [propA.a, propB.x.y]);
51 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
51 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source (6:14)
52
53 -CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
53 +CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source (6:14)
54 15 | }
55 16 |
56 17 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-invalid-useCallback-read-maybeRef.expect.md
+1 -1
@@ -24,7 +24,7 @@ function useHook(maybeRef) {
24 > 6 | return [maybeRef.current];
25 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 > 7 | }, [maybeRef]);
27 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:7)
27 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `maybeRef.current`, but the source dependencies were [maybeRef]. Differences in ref.current access (5:7)
28 8 | }
29 9 |
30 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-invalid-useMemo-read-maybeRef.expect.md
+1 -1
@@ -24,7 +24,7 @@ function useHook(maybeRef, shouldRead) {
24 > 6 | return () => [maybeRef.current];
25 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 > 7 | }, [shouldRead, maybeRef]);
27 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:7)
27 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `maybeRef.current`, but the source dependencies were [shouldRead, maybeRef]. Differences in ref.current access (5:7)
28 8 | }
29 9 |
30 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.expect.md
+1 -1
@@ -39,7 +39,7 @@ export const FIXTURE_ENTRYPOINT = {
39 > 12 | }
40 | ^^^^^^^^^^^^^^^^^^^^^^
41 > 13 | }, []);
42 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (9:13)
42 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `ref`, but the source dependencies were []. Inferred dependency not present in source (9:13)
43 14 | }
44 15 |
45 16 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.expect.md
+1 -1
@@ -22,7 +22,7 @@ function useHook(x) {
22 7 | const aliasedProp = x.y.z;
23 8 |
24 > 9 | return useCallback(() => [aliasedX, x.y.z], [x, aliasedProp]);
25 - | ^^^^^^^^^^^^^^^^^^^^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (9:9)
25 + | ^^^^^^^^^^^^^^^^^^^^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `aliasedX`, but the source dependencies were [x, aliasedProp]. Inferred different dependency than source (9:9)
26 10 | }
27 11 |
28 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.expect.md
+1 -1
@@ -38,7 +38,7 @@ export const FIXTURE_ENTRYPOINT = {
38 > 9 | };
39 | ^^^^^^^^^^^^
40 > 10 | }, [propA, propB.x.y]);
41 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:10)
41 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB?.x.y`, but the source dependencies were [propA, propB.x.y]. Inferred different dependency than source (5:10)
42 11 | }
43 12 |
44 13 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.expect.md
+1 -1
@@ -43,7 +43,7 @@ function Component({propA, propB}) {
43 > 13 | }
44 | ^^^^^^^^^^^^^^^^^
45 > 14 | }, [propA?.a, propB.x.y]);
46 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
46 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA?.a, propB.x.y]. Inferred less specific property than source (6:14)
47 15 | }
48 16 |
49 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.expect.md
+1 -1
@@ -24,7 +24,7 @@ function Component({propA}) {
24 > 6 | return propA.x();
25 | ^^^^^^^^^^^^^^^^^^^^^
26 > 7 | }, [propA.x]);
27 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:7)
27 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source (5:7)
28 8 | }
29 9 |
30 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.expect.md
+1 -1
@@ -22,7 +22,7 @@ function useHook(x) {
22 7 | const aliasedProp = x.y.z;
23 8 |
24 > 9 | return useMemo(() => [x, x.y.z], [aliasedX, aliasedProp]);
25 - | ^^^^^^^^^^^^^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (9:9)
25 + | ^^^^^^^^^^^^^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `x`, but the source dependencies were [aliasedX, aliasedProp]. Inferred different dependency than source (9:9)
26 10 | }
27 11 |
28 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.expect.md
+1 -1
@@ -43,7 +43,7 @@ function Component({propA, propB}) {
43 > 13 | }
44 | ^^^^^^^^^^^^^^^^^
45 > 14 | }, [propA?.a, propB.x.y]);
46 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
46 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA?.a, propB.x.y]. Inferred less specific property than source (6:14)
47 15 | }
48 16 |
49 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.expect.md
+2 -2
@@ -43,9 +43,9 @@ function Component({propA, propB}) {
43 > 13 | }
44 | ^^^^^^^^^^^^^^^^^
45 > 14 | }, [propA.a, propB.x.y]);
46 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
46 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source (6:14)
47
48 -CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (6:14)
48 +CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source (6:14)
49 15 | }
50 16 |
51 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.expect.md
+1 -1
@@ -30,7 +30,7 @@ function Component({propA}) {
30 > 8 | };
31 | ^^^^^^^^^^^^
32 > 9 | }, [propA.x]);
33 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:9)
33 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source (5:9)
34 10 | }
35 11 |
36 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.expect.md
+1 -1
@@ -24,7 +24,7 @@ function Component({propA}) {
24 > 6 | return propA.x();
25 | ^^^^^^^^^^^^^^^^^^^^^
26 > 7 | }, [propA.x]);
27 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (5:7)
27 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source (5:7)
28 8 | }
29 9 |
30 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.expect.md
+1 -1
@@ -37,7 +37,7 @@ function useFoo(input1) {
37 > 17 | return [y];
38 | ^^^^^^^^^^^^^^^
39 > 18 | }, [(mutate(x), y)]);
40 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (16:18)
40 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `input1`, but the source dependencies were [y]. Inferred different dependency than source (16:18)
41 19 |
42 20 | return [x, memoized];
43 21 | }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.expect.md
+1 -1
@@ -41,7 +41,7 @@ function Component(props) {
41 > 10 | return x;
42 | ^^^^^^^^^^^^^^^^^
43 > 11 | }, [props?.items, props.cond]);
44 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (4:11)
44 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source (4:11)
45 12 | return (
46 13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
47 14 | );
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.expect.md
+1 -1
@@ -41,7 +41,7 @@ function Component(props) {
41 > 10 | return x;
42 | ^^^^^^^^^^^^^^^^^
43 > 11 | }, [props?.items, props.cond]);
44 - | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (4:11)
44 + | ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source (4:11)
45 12 | return (
46 13 | <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
47 14 | );