@@ -15,6 +15,7 @@ import {format, formatWithStyles} from './utils';
15
15
import { getInternalReactConstants } from './renderer' ;
16
16
import { getStackByFiberInDevAndProd } from './DevToolsFiberComponentStack' ;
17
17
import { consoleManagedByDevToolsDuringStrictMode } from 'react-devtools-feature-flags' ;
18
+ import { castBool , castBrowserTheme } from '../utils' ;
18
19
19
20
const OVERRIDE_CONSOLE_METHODS = [ 'error' , 'trace' , 'warn' ] ;
20
21
const DIMMED_NODE_CONSOLE_COLOR = '\x1b[2m%s\x1b[0m' ;
@@ -143,6 +144,14 @@ const consoleSettingsRef = {
143
144
browserTheme : 'dark' ,
144
145
} ;
145
146
147
+ export type ConsolePatchSettings = {
148
+ appendComponentStack : boolean ,
149
+ breakOnConsoleErrors : boolean ,
150
+ showInlineWarningsAndErrors : boolean ,
151
+ hideConsoleLogsInStrictMode : boolean ,
152
+ browserTheme : BrowserTheme ,
153
+ } ;
154
+
146
155
// Patches console methods to append component stack for the current fiber.
147
156
// Call unpatch() to remove the injected behavior.
148
157
export function patch ( {
@@ -151,13 +160,7 @@ export function patch({
151
160
showInlineWarningsAndErrors,
152
161
hideConsoleLogsInStrictMode,
153
162
browserTheme,
154
- } : {
155
- appendComponentStack : boolean ,
156
- breakOnConsoleErrors : boolean ,
157
- showInlineWarningsAndErrors : boolean ,
158
- hideConsoleLogsInStrictMode : boolean ,
159
- browserTheme : BrowserTheme ,
160
- } ) : void {
163
+ } : ConsolePatchSettings ) : void {
161
164
// Settings may change after we've patched the console.
162
165
// Using a shared ref allows the patch function to read the latest values.
163
166
consoleSettingsRef . appendComponentStack = appendComponentStack ;
@@ -390,14 +393,19 @@ export function patchConsoleUsingWindowValues() {
390
393
} ) ;
391
394
}
392
395
393
- function castBool ( v : any ) : ?boolean {
394
- if ( v === true || v === false ) {
395
- return v ;
396
- }
397
- }
398
-
399
- function castBrowserTheme ( v : any ) : ?BrowserTheme {
400
- if ( v === 'light' || v === 'dark' || v === 'auto' ) {
401
- return v ;
402
- }
396
+ // After receiving cached console patch settings from React Native, we set them on window.
397
+ // When the console is initially patched (in renderer.js and hook.js), these values are read.
398
+ // The browser extension (etc.) sets these values on window, but through another method.
399
+ export function writeConsolePatchSettingsToWindow (
400
+ settings : ConsolePatchSettings ,
401
+ ) : void {
402
+ window. __REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ =
403
+ settings . appendComponentStack ;
404
+ window . __REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ =
405
+ settings . breakOnConsoleErrors ;
406
+ window . __REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ =
407
+ settings . showInlineWarningsAndErrors ;
408
+ window . __REACT_DEVTOOLS_HIDE_CONSOLE_LOGS_IN_STRICT_MODE__ =
409
+ settings . hideConsoleLogsInStrictMode ;
410
+ window . __REACT_DEVTOOLS_BROWSER_THEME__ = settings . browserTheme ;
403
411
}
0 commit comments