dillon1000/react

Commit

refactor[devtools]: forbid editing class instances in props (#26522)

## Summary
Fixes https://github.com/facebook/react/issues/24781

Restricting from editing props, which are class instances, because their
internals should be opaque.

Proposed changes:
1. Adding new data type `class_instance`: based on prototype chain of an
object we will check if its plain or not. If not, then will be marked as
`class_instance`. This should not affect `arrays`, ..., because we do
this in the end of an `object` case in `getDataType` function.

Important detail: this approach won't work for objects created with
`Object.create`, because of the custom prototype. This can also be
bypassed by manually deleting a prototype ¯\\\_(ツ)_/¯
I am not sure if there might be a better solution (which will cover all
cases) to detect if object is a class instance. Initially I was trying
to use `Object.getPrototypeOf(object) === Object.prototype`, but this
won't work for cases when we are dealing with `iframe`.


2. Objects with a type `class_instance` will be marked as unserializable
and read-only.

## Demo
`person` is a class instance, `object` is a plain object


https://user-images.githubusercontent.com/28902667/228914791-ebdc8ab0-eb5c-426d-8163-66d56b5e8790.mov
Browse files
Changed paths5 files
First-parent comparison
M fixtures/devtools/standalone/index.html ModifiedM packages/react-devtools-shared/src/__tests__/utils-test.js ModifiedM packages/react-devtools-shared/src/hydration.js ModifiedM packages/react-devtools-shared/src/utils.js ModifiedM packages/react-devtools-shell/src/app/InspectableElements/UnserializableProps.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…