fix value formatting of proxies of class instances #30880
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For Hookstate Proxies of class instances,
data.constructor.name
returnsProxy({})
, so useObject.getPrototypeOf(data).constructor.name
instead, which works correctly from my testing.Summary
React DevTools immediately bricks itself if you inspect any component that has a prop that is a Hookstate that wraps a class instance ... because these are proxies where
data.constructor.name
returns some un-cloneable object, butObject.getPrototypeOf(data)
doesn't returnObject
(it returns the prototype of the class inside).How did you test this change?
This part of the code has no associated tests at all.
Technically,
packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js
exists, but I triedyarn test
and these tests aren't even executed anymore. I can't figure it out, so whatever.If you run this code:
then
instanceProxy.constructor.name
returns some proxy that cannot be cloned, butObject.getPrototypeOf(instanceProxy).constructor.name
returns the correct value.This PR fixes the devtools to use
Object.getPrototypeOf(instanceProxy).constructor.name
.I modified my local copy of devtools to use this method and it fixed the bricking that I experienced.
Related #29954