[compiler] Fix JSX tags with underscore-prefix incorrectly treated as host components#36686
[compiler] Fix JSX tags with underscore-prefix incorrectly treated as host components#36686amitsaroj wants to merge 3 commits into
Conversation
|
Hi @amitsaroj! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Fixes #36601
In
lowerJsxElementName(BuildHIR.ts), the check used to distinguish user-defined component tags from host (builtin) element tags was:The JSX convention (and the React runtime) is: a tag is a host element if and only if its first character is a lowercase ASCII letter
[a-z]. Any other first character — including_,$, or an uppercase letter — means the tag is a user-defined component.The old regex
^[A-Z]only matched tags beginning with an uppercase letter, so tags like<_Bar>or<$Special>fell through to theBuiltinTagbranch and their values were never tracked as dependencies. This produced silently incorrect memoization —_Barwas treated as a stable builtin tag even though it is a prop that could change between renders.Fix
Change the condition to its logical inverse:
This preserves the existing behaviour for the common cases:
div,span,button, … → still BuiltinTag (start with[a-z])Button,MyComponent, … → still component (start with[A-Z], not[a-z])And now correctly handles:
_Bar,_Foo→ component (not[a-z]→ now takes the component path) ✓$Special→ component (not[a-z]) ✓Test plan
Added a regression test fixture at:
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-underscore-prefix-component.jsRun the compiler test suite to generate the updated snapshot:
Repro (from issue #36601)
Before fix:
_Barwas treated as aBuiltinTag. The JSX was memoized with zero dependencies — changes to_Baracross renders were silently ignored.After fix:
_Baris correctly treated as a component reference, loaded from scope and tracked as a dependency.