fix(react-is): support legacy React elements (react.element)#36420
fix(react-is): support legacy React elements (react.element)#36420Liuwei1125 wants to merge 1 commit intofacebook:mainfrom
Conversation
React 19 changed $$typeof from Symbol('react.element') to
Symbol('react.transitional.element'). The react-is package only
checked for the new symbol, breaking backward compatibility with
React 17/18 elements.
This fix updates isElement() and typeOf() to also recognize
REACT_LEGACY_ELEMENT_TYPE, ensuring tools that upgrade to react-is@19
can still identify elements created by older React versions.
Fixes facebook#36409
Closes facebook#36409
|
Hi @Liuwei1125! 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! |
|
I have signed the Meta CLA. Please re-check. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Bug Fix Summary
Issue: #36409 -
react-is@19does not recognise elements from React 18Problem
React 19 changed $$typeof from
Symbol('react.element')toSymbol('react.transitional.element'). The react-is@19 package only checks for the new symbol, breaking backward compatibility with React 17/18 elements.Solution
Update
isElement()andtypeOf()inpackages/react-is/src/ReactIs.jsto also recognizeREACT_LEGACY_ELEMENT_TYPE.Changes
ReactIs.js: Import
REACT_LEGACY_ELEMENT_TYPEand add it to:typeOf()switch statementisElement()checkReactIs-test.js: Add test case
should identify legacy elements from older React versionsTesting
This fix ensures tools that upgrade to
react-is@19(like jest's pretty-format) can still identify elements created by React 17/18 without requiring users to upgrade React.