WIP: Improve console dimming on second StrictMode render #24306
Closed
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.
Summary
Fixes #24302. The goal is to apply dimming only to string values to avoid interfering with printing and introspection of complex values.
This PR isn't ready for review yet. Putting it up to show a working implementation, but:
format
implementation in thebackend/
directory. The one inhook.js
has only one callsite but the one inbackend/
has several, some of which seem unrelated to browser console formatting. I don't have any knowledge of the devtools architecture so it'll take me some time to understand.Implementation notes
The console API has two forms:
['%cA %s', 'color: blue', 'B', 'C']
.['A', 'B', 'C']
.Colors can only be applied using the first form, and only to the contents of the placeholder string. So the basic idea is to coerce the argument list into the placeholder form, apply the color directives, and append additional placeholders for all arguments without one. Some examples of this translation:
['A', 1, 'B']
=>['%c%s %o %s', 'color: X', 'A', 1, 'B']
['A %d', 1, 'B']
=>['%cA %d %c%s', 'color: X', 1, 'color: X', 'B']
['A%cB', 'color: blue', 'C']
=>['%cA%cB %c%s', 'color: X', 'color: blue', 'color: X', 'C']
How did you test this change?
TBD