Skip to content

Commit c664b9b

Browse files
committed
Remove the actual "renderer" from registerRenderer
These internals are not needed. All we need is the onErrorOrWarning and getComponentStack helpers.
1 parent a09d1c7 commit c664b9b

File tree

4 files changed

+13
-40
lines changed

4 files changed

+13
-40
lines changed

packages/react-devtools-shared/src/__tests__/console-test.js

-1
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ describe('console error', () => {
10931093
inject(internals);
10941094

10951095
Console.registerRenderer(
1096-
internals,
10971096
() => {
10981097
throw Error('foo');
10991098
},

packages/react-devtools-shared/src/backend/console.js

+11-37
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
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

1912
import {
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';
2921
import {castBool, castBrowserTheme} from '../utils';
3022

3123
const 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

10288
let targetConsole: Object = console;
10389
let 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).
127113
export 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

149123
const 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) {

packages/react-devtools-shared/src/backend/fiber/renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ export function attach(
12011201
// Patching the console enables DevTools to do a few useful things:
12021202
// * Append component stacks to warnings and error messages
12031203
// * Disable logging during re-renders to inspect hooks (see inspectHooksOfFiber)
1204-
registerRendererWithConsole(renderer, onErrorOrWarning, getComponentStack);
1204+
registerRendererWithConsole(onErrorOrWarning, getComponentStack);
12051205

12061206
// The renderer interface can't read these preferences directly,
12071207
// because it is stored in localStorage within the context of the extension.

packages/react-devtools-shared/src/backend/flight/renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function attach(
2121
global: Object,
2222
): RendererInterface {
2323
patchConsoleUsingWindowValues();
24-
registerRendererWithConsole(renderer);
24+
registerRendererWithConsole(); // TODO: Fill in the impl
2525

2626
return {
2727
cleanup() {},

0 commit comments

Comments
 (0)