dillon1000/react

Commit

don't stringify objects for console log second render (#24373)

Fixes #24302 based on #24306.
---

The current implementation for strict mode double logging stringiness and dims the second log. However, because we stringify everything, including objects, this causes objects to be logged as `[object Object]` etc.

This PR creates a new function that formats console log arguments with a specified style. It does this by:
1. The first param is a string that contains %c: Bail out and return the args without modifying the styles. We don't want to affect styles that the developer deliberately set.
2. The first param is a string that doesn't contain %c but contains string formatting: `[`%c${args[0]}`, style, ...args.slice(1)]` Note: we assume that the string formatting that the developer uses is correct.
3. The first param is a string that doesn't contain string formatting OR is not a string: Create a formatting string where:
   -  boolean, string, symbol -> %s
   -  number -> %f OR %i depending on if it's an int or float
   -  default -> %o
---
Co-authored-by: Billy Janitsch <[email protected]>
Browse files
Changed paths5 files
First-parent comparison
M packages/react-devtools-shared/src/__tests__/console-test.js ModifiedM packages/react-devtools-shared/src/__tests__/utils-test.js ModifiedM packages/react-devtools-shared/src/backend/console.js ModifiedM packages/react-devtools-shared/src/backend/utils.js ModifiedM packages/react-devtools-shared/src/hook.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…