77 * @flow
88 */
99
10- import type { Fiber } from 'react-reconciler/src/ReactInternalTypes' ;
11- import type {
12- LegacyDispatcherRef ,
13- CurrentDispatcherRef ,
14- ReactRenderer ,
15- WorkTagMap ,
16- ConsolePatchSettings ,
17- } from './types' ;
10+ import type { ConsolePatchSettings } from './types' ;
1811
1912import {
2013 formatConsoleArguments ,
@@ -25,7 +18,6 @@ import {
2518 ANSI_STYLE_DIMMING_TEMPLATE ,
2619 ANSI_STYLE_DIMMING_TEMPLATE_WITH_COMPONENT_STACK ,
2720} from 'react-devtools-shared/src/constants' ;
28- import { getInternalReactConstants } from './fiber/renderer' ;
2921import { castBool , castBrowserTheme } from '../utils' ;
3022
3123const OVERRIDE_CONSOLE_METHODS = [ 'error' , 'trace' , 'warn' ] ;
@@ -88,16 +80,10 @@ type GetComponentStack = (
8880 topFrame : Error ,
8981) => null | { enableOwnerStacks : boolean , componentStack : string } ;
9082
91- const injectedRenderers : Map <
92- ReactRenderer ,
93- {
94- currentDispatcherRef : LegacyDispatcherRef | CurrentDispatcherRef ,
95- getCurrentFiber : ( ) => Fiber | null ,
96- onErrorOrWarning : ?OnErrorOrWarning ,
97- workTagMap : WorkTagMap ,
98- getComponentStack : ?GetComponentStack ,
99- } ,
100- > = new Map ( ) ;
83+ const injectedRenderers : Array < {
84+ onErrorOrWarning : ?OnErrorOrWarning ,
85+ getComponentStack : ?GetComponentStack ,
86+ } > = [ ] ;
10187
10288let targetConsole : Object = console ;
10389let targetConsoleMethods : { [ string ] : $FlowFixMe } = { } ;
@@ -125,25 +111,13 @@ export function dangerous_setTargetConsoleForTesting(
125111// These internals will be used if the console is patched.
126112// Injecting them separately allows the console to easily be patched or un-patched later (at runtime).
127113export function registerRenderer (
128- renderer : ReactRenderer ,
129114 onErrorOrWarning ?: OnErrorOrWarning ,
130115 getComponentStack ?: GetComponentStack ,
131116) : void {
132- const { currentDispatcherRef, getCurrentFiber, version} = renderer ;
133-
134- // currentDispatcherRef gets injected for v16.8+ to support hooks inspection.
135- // getCurrentFiber gets injected for v16.9+.
136- if ( currentDispatcherRef != null && typeof getCurrentFiber === 'function' ) {
137- const { ReactTypeOfWork } = getInternalReactConstants ( version ) ;
138-
139- injectedRenderers . set ( renderer , {
140- currentDispatcherRef,
141- getCurrentFiber,
142- workTagMap : ReactTypeOfWork ,
143- onErrorOrWarning,
144- getComponentStack,
145- } ) ;
146- }
117+ injectedRenderers . push ( {
118+ onErrorOrWarning ,
119+ getComponentStack ,
120+ } ) ;
147121}
148122
149123const consoleSettingsRef : ConsolePatchSettings = {
@@ -214,8 +188,8 @@ export function patch({
214188
215189 // Search for the first renderer that has a current Fiber.
216190 // We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
217- // eslint-disable-next-line no-for-of-loops/no-for-of-loops
218- for ( const renderer of injectedRenderers . values ( ) ) {
191+ for ( let i = 0 ; i < injectedRenderers . length ; i ++ ) {
192+ const renderer = injectedRenderers [ i ] ;
219193 const { getComponentStack, onErrorOrWarning} = renderer ;
220194 try {
221195 if ( shouldShowInlineWarningsAndErrors ) {
0 commit comments