Skip to content

Comments

Fix preserve-manual-memoization false positive with optional chaining deps#35859

Open
sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor:fix-35577
Open

Fix preserve-manual-memoization false positive with optional chaining deps#35859
sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor:fix-35577

Conversation

@sleitor
Copy link

@sleitor sleitor commented Feb 21, 2026

Summary

When a dependency array uses optional chaining (e.g. [obj?.id]), the compiler may infer a less specific dependency (e.g. obj) because optional chain lowering introduces conditionals. Previously this triggered a Subpath error ("Inferred less specific property than source"), but the user's more specific optional dependency is semantically correct — using ?. acknowledges the conditionality and produces undefined when the base is nullish.

This change treats the inferred-less-specific case as OK when the source dependency continues with an optional property access from where the inferred dependency ends. Non-optional source deps that are more specific than inferred deps still correctly produce the Subpath error.

Test

Added useCallback-optional-chaining-dep test fixture that reproduces the exact pattern from #35577. All 1712 existing tests pass.

Fixes #35577
Fixes #35167

… deps

When a dependency array uses optional chaining (e.g. [obj?.id]), the compiler
may infer a less specific dependency (e.g. obj) because optional chain lowering
introduces conditionals. Previously this triggered a Subpath error, but the
user's more specific optional dependency is semantically correct — using ?.
acknowledges the conditionality and produces undefined when the base is nullish.

This change treats the inferred-less-specific case as OK when the source
dependency continues with an optional property access from where the inferred
dependency ends.

Fixes facebook#35577
Fixes facebook#35167
@meta-cla meta-cla bot added the CLA Signed label Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant