7
7
* @flow
8
8
*/
9
9
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' ;
18
11
19
12
import {
20
13
formatConsoleArguments ,
@@ -25,7 +18,6 @@ import {
25
18
ANSI_STYLE_DIMMING_TEMPLATE ,
26
19
ANSI_STYLE_DIMMING_TEMPLATE_WITH_COMPONENT_STACK ,
27
20
} from 'react-devtools-shared/src/constants' ;
28
- import { getInternalReactConstants } from './fiber/renderer' ;
29
21
import { castBool , castBrowserTheme } from '../utils' ;
30
22
31
23
const OVERRIDE_CONSOLE_METHODS = [ 'error' , 'trace' , 'warn' ] ;
@@ -88,16 +80,10 @@ type GetComponentStack = (
88
80
topFrame : Error ,
89
81
) => null | { enableOwnerStacks : boolean , componentStack : string } ;
90
82
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
+ } > = [ ] ;
101
87
102
88
let targetConsole : Object = console ;
103
89
let targetConsoleMethods : { [ string ] : $FlowFixMe } = { } ;
@@ -125,25 +111,13 @@ export function dangerous_setTargetConsoleForTesting(
125
111
// These internals will be used if the console is patched.
126
112
// Injecting them separately allows the console to easily be patched or un-patched later (at runtime).
127
113
export function registerRenderer (
128
- renderer : ReactRenderer ,
129
114
onErrorOrWarning ?: OnErrorOrWarning ,
130
115
getComponentStack ?: GetComponentStack ,
131
116
) : 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
+ } ) ;
147
121
}
148
122
149
123
const consoleSettingsRef : ConsolePatchSettings = {
@@ -214,8 +188,8 @@ export function patch({
214
188
215
189
// Search for the first renderer that has a current Fiber.
216
190
// 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 ] ;
219
193
const { getComponentStack, onErrorOrWarning} = renderer ;
220
194
try {
221
195
if ( shouldShowInlineWarningsAndErrors ) {
0 commit comments