Skip to content

Conversation

@kenanAST
Copy link

Summary

Fixes #35379

When a component is named Symbol, it shadows the global Symbol object. The compiler currently emits Symbol.for("react.memo_cache_sentinel") for memoization checks, which breaks at runtime because it tries to call .for() on the React component instead of the global Symbol.

This changes the codegen to use globalThis.Symbol.for() instead, which works regardless of local shadowing. The same fix is applied to the runtime package.

How did you test this change?

Updated the test fixtures to verify the new output format. The generated code now uses:

if ($[0] === globalThis.Symbol.for("react.memo_cache_sentinel")) {

This matches the approach used in Babel's own codebase (see babel/babel#3250) where they had the same shadowing issue.

@meta-cla
Copy link

meta-cla bot commented Dec 31, 2025

Hi @kenanAST!

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 [email protected]. Thanks!

@kenanAST kenanAST force-pushed the fix-symbol-shadowing branch from ab84dbd to 00f8f7b Compare December 31, 2025 08:15
@kenanAST kenanAST closed this Dec 31, 2025
@kenanAST kenanAST deleted the fix-symbol-shadowing branch December 31, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React Compiler generates erroneous code when an app contains a component named Symbol

1 participant