dillon1000/react

Commit

[devtools] allow non-coercible objects in formatConsoleArgumentsToSingleString (#31444)

## Summary

We have been getting unhandled `TypeError: Cannot convert object to
primitive value` errors in development that only occur when using
devtools. I tracked it down to `console.error()` calls coming from
Apollo Client where one of the arguments is an object without a
prototype (created with `Object.create(null)`). This causes
`formatConsoleArgumentsToSingleString()` in React's devtools to error as
the function does not defend against `String()` throwing an error.

My attempted fix is to introduce a `safeToString` function (naming
suggestions appreciated) which expects `String()` to throw on certain
object and in that case falls back to returning `[object Object]`, which
is what `String({})` would return.

## How did you test this change?

Added a new unit test.
Browse files
Changed paths2 files
First-parent comparison
M packages/react-devtools-shared/src/__tests__/utils-test.js ModifiedM packages/react-devtools-shared/src/backend/utils/index.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…