Skip to content

Commit 83cb283

Browse files
committed
refactor[RendererInterface]: expose onErrorOrWarning and getComponentStack
1 parent d160aa0 commit 83cb283

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
* @flow
88
*/
99

10-
import type {ConsolePatchSettings} from './types';
10+
import type {
11+
ConsolePatchSettings,
12+
OnErrorOrWarning,
13+
GetComponentStack,
14+
} from './types';
1115

1216
import {
1317
formatConsoleArguments,
@@ -75,11 +79,6 @@ function restorePotentiallyModifiedArgs(args: Array<any>): Array<any> {
7579
}
7680
}
7781

78-
type OnErrorOrWarning = (type: 'error' | 'warn', args: Array<any>) => void;
79-
type GetComponentStack = (
80-
topFrame: Error,
81-
) => null | {enableOwnerStacks: boolean, componentStack: string};
82-
8382
const injectedRenderers: Array<{
8483
onErrorOrWarning: ?OnErrorOrWarning,
8584
getComponentStack: ?GetComponentStack,

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

+2
Original file line numberDiff line numberDiff line change
@@ -5789,8 +5789,10 @@ export function attach(
57895789
inspectElement,
57905790
logElementToConsole,
57915791
patchConsoleForStrictMode,
5792+
getComponentStack,
57925793
getElementAttributeByPath,
57935794
getElementSourceFunctionById,
5795+
onErrorOrWarning,
57945796
overrideError,
57955797
overrideSuspense,
57965798
overrideValueAtPath,

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

+10
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ export type InstanceAndStyle = {
350350

351351
type Type = 'props' | 'hooks' | 'state' | 'context';
352352

353+
export type OnErrorOrWarning = (
354+
type: 'error' | 'warn',
355+
args: Array<any>,
356+
) => void;
357+
export type GetComponentStack = (
358+
topFrame: Error,
359+
) => null | {enableOwnerStacks: boolean, componentStack: string};
360+
353361
export type RendererInterface = {
354362
cleanup: () => void,
355363
clearErrorsAndWarnings: () => void,
@@ -364,6 +372,7 @@ export type RendererInterface = {
364372
findHostInstancesForElementID: FindHostInstancesForElementID,
365373
flushInitialOperations: () => void,
366374
getBestMatchForTrackedPath: () => PathMatch | null,
375+
getComponentStack?: GetComponentStack,
367376
getNearestMountedDOMNode: (component: Element) => Element | null,
368377
getElementIDForHostInstance: GetElementIDForHostInstance,
369378
getDisplayNameForElementID: GetDisplayNameForElementID,
@@ -386,6 +395,7 @@ export type RendererInterface = {
386395
forceFullData: boolean,
387396
) => InspectedElementPayload,
388397
logElementToConsole: (id: number) => void,
398+
onErrorOrWarning?: OnErrorOrWarning,
389399
overrideError: (id: number, forceError: boolean) => void,
390400
overrideSuspense: (id: number, forceFallback: boolean) => void,
391401
overrideValueAtPath: (

0 commit comments

Comments
 (0)