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/;
51
51
// method has been overridden by the patchForStrictMode function.
52
52
// If it has we'll need to do some special formatting of the arguments
53
53
// so the console color stays consistent
54
- function isStrictModeOverride ( args : Array < string > ) : boolean {
54
+ function isStrictModeOverride ( args : Array < any > ) : boolean {
55
55
if ( __IS_FIREFOX__ ) {
56
56
return (
57
57
args . length >= 2 &&
@@ -63,6 +63,21 @@ function isStrictModeOverride(args: Array<string>): boolean {
63
63
}
64
64
}
65
65
66
+ function restorePotentiallyModifiedArgs ( 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
+
66
81
type OnErrorOrWarning = (
67
82
fiber : Fiber ,
68
83
type : 'error' | 'warn' ,
@@ -220,8 +235,8 @@ export function patch({
220
235
onErrorOrWarning (
221
236
current ,
222
237
( ( 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
+ restorePotentiallyModifiedArgs ( args ) ,
225
240
) ;
226
241
}
227
242
}
You can’t perform that action at this time.
0 commit comments