Bug: The invalid value warning was showed when adding functions to object prototype
While adding a function to Object.prototype in React project anywhere, react while showing the Warning: Invalid value for prop `xxx` on tag. And an uncaught TypeError.
React version: 17.0.2
Steps To Reproduce
- Create a react project with create-react-app
- Put the following code anywhere in the project:
Object.prototype.test = function () {}
The current behavior
Getting the warning
Also the Uncaught TypeError: renderer.setTraceUpdatesEnabled is not a function.

The expected behavior
Expected nether warning nor error.
Object.prototype.test = function () {}
This adds an enumerable property to every object in your entire JS context. In a normal JS environment, this is not the case; for instance, { a: 3, b: 4 } has exactly two enumerable properties normally, "a", and "b".
You probably shouldn't make this change. Even if the React team is willing to support it, many other libraries will assume you haven't mucked up Object.prototype with extra enumerable junk. for .. in loops oftentimes don't have own property guards on them because in a regular JS environment, you don't need them.
If you absolutely have to do this, you should make the property non-enumerable.
Thanks for the that save me a lot of time!
Yeah patching the object prototype isn't supported.