[Compiler] Fix 'use no memo' to apply recursively to nested functions #35433
+421
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed bug #35350 where the
'use no memo'directive did not apply recursively to nested functions with component-like names. This caused runtime hook errors when nested functions were compiled and used as render props (e.g. with react-virtualized).The fix:
'use no memo'during traversal'use memo'on a nested function to override the parent opt-outTest Plan:
Fixes: #35350
Summary
The React Compiler previously treated
'use no memo'as applying only to the annotated function. Nested functions with component-like names were still compiled, even when they were intended to be called as plain functions.This caused invalid hook usage at runtime in render prop patterns commonly used by libraries such as react-virtualized.
This change makes
'use no memo'act as a recursive opt-out boundary for nested functions, unless a nested function explicitly opts back in with'use memo'.How did you test this change?
Added new test fixtures under
compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/:use-no-memo-nested-component.jsuse-no-memo-nested-arrow.jsuse-no-memo-deeply-nested.jsuse-no-memo-nested-with-opt-in.jsRan targeted tests:
yarn snap -p "use-no-memo*"Verification Results
$ yarn snap1832 Tests, 1832 Passed, 0 Failed
Done in 23.93s.