File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
packages/react-devtools-shared/src/backend Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ const STYLE_DIRECTIVE_REGEX = /^%c/;
5151// method has been overridden by the patchForStrictMode function.
5252// If it has we'll need to do some special formatting of the arguments
5353// so the console color stays consistent
54- function isStrictModeOverride ( args : Array < string > ) : boolean {
54+ function isStrictModeOverride ( args : Array < any > ) : boolean {
5555 if ( __IS_FIREFOX__ ) {
5656 return (
5757 args . length >= 2 &&
@@ -63,6 +63,21 @@ function isStrictModeOverride(args: Array<string>): boolean {
6363 }
6464}
6565
66+ function potentiallyRestoreOriginalArgs ( args : Array < any > ) : Array < any > {
67+ // If the arguments don't have any styles applied, then just copy
68+ if ( ! isStrictModeOverride ( args ) ) {
69+ return args . slice ( ) ;
70+ }
71+
72+ if ( __IS_FIREFOX__ ) {
73+ // Filter out %c from the start of the first argument and color as a second argument
74+ return [ args [ 0 ] . slice ( 2 ) ] . concat ( args . slice ( 2 ) ) ;
75+ } else {
76+ // Filter out the `\x1b...%s\x1b` template
77+ return args . slice ( 1 ) ;
78+ }
79+ }
80+
6681type OnErrorOrWarning = (
6782 fiber : Fiber ,
6883 type : 'error' | 'warn' ,
@@ -220,8 +235,8 @@ export function patch({
220235 onErrorOrWarning (
221236 current ,
222237 ( ( method : any ) : 'error' | 'warn' ) ,
223- // Copy args before we mutate them (e.g. adding the component stack)
224- args . slice ( ) ,
238+ // Potentially restore and copy args before we mutate them (e.g. adding the component stack)
239+ potentiallyRestoreOriginalArgs ( args ) ,
225240 ) ;
226241 }
227242 }
You can’t perform that action at this time.
0 commit comments