Repository navigation
Fix TypeError in CheckStringCoercion typeName() for null-prototype objects in DEV - #37900
prasad2512 wants to merge 1 commit into
Conversation
|
Hi @prasad2512! 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 [email protected]. Thanks! |
d81879c to
4c7b4a2
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
4c7b4a2 to
c55c1b5
Compare
|
Hi @eps1lon, rebased onto latest main with CLA verified. Includes regression test in ReactIdentity-test for null-prototype objects in typeName(). Ready for review when convenient. Thanks! |
Summary
Fixes #37881
In development mode (
__DEV__),typeName(value)inpackages/shared/CheckStringCoercion.jsconstructs a human-readable diagnostic type string when a prop, key, attribute, or style value throws during string coercion ('' + value).Currently,
typeName(value)accesses(value as any).constructor.name:When
valueis created without a prototype (e.g.Object.create(null)or{ __proto__: null }),(value as any).constructorisundefined. Accessing.nameonundefinedcauses an unhandled runtime error:This crashes React's internal DEV helper before React can log the diagnostic error message and troubleshooting recommendations.
This PR safely checks for
constructorexistence before accessing.name:When
constructorisundefinedor null, it gracefully falls back to'Object'.How did you test this change?
packages/react-dom/src/__tests__/ReactIdentity-test.jsverifying that passing a null-prototype object with a throwingvalueOfdoes not crashtypeName(), properly prints the diagnostic error message (The provided key is an unsupported type Object. This value must be coerced to a string before using it here.), and throws the expected coercion exception.