Skip to content

Conversation

@sahiee-dev
Copy link

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:

  1. Track functions that declare 'use no memo' during traversal
  2. Skip compiling nested functions if any ancestor has opted out
  3. Allow explicit 'use memo' on a nested function to override the parent opt-out

Test Plan:

  • Added new compiler fixtures covering nested, deeply nested, arrow function, and explicit opt-in cases
  • All existing tests pass with no regressions

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.js
  • use-no-memo-nested-arrow.js
  • use-no-memo-deeply-nested.js
  • use-no-memo-nested-with-opt-in.js

Ran targeted tests:

yarn snap -p "use-no-memo*"

Verification Results

$ yarn snap
1832 Tests, 1832 Passed, 0 Failed
Done in 23.93s.

Summary:
Fixed bug facebook#35350 where 'use no memo' directive didn't apply recursively to
nested functions with component-like names. This caused runtime errors when
using render props with libraries like react-virtualized.

The fix:
1. Track functions with 'use no memo' in a Set during traversal
2. Before compiling any nested function, check if any ancestor has opted out
3. Allow explicit 'use memo' in nested function to override parent's opt-out

Test Plan:
- Added 4 new test fixtures covering nested function scenarios
- All 1832 existing tests pass with no regressions

Fixes: facebook#35350
@meta-cla
Copy link

meta-cla bot commented Jan 1, 2026

Hi @sahiee-dev!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Jan 1, 2026
@meta-cla
Copy link

meta-cla bot commented Jan 1, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: 'use no memo' does not apply recursively

1 participant