fix[rdt/fiber/renderer.js]: getCurrentFiber can be injected as null (#30968)
In production artifacts for `18.x.x` `getCurrentFiber` can actually be injected as `null`. Updated `getComponentStack` and `onErrorOrWarning` implementations to support this. 
Ruslan Lesiutin committed
Sep 16, 2024 at 14:47 UTC
8cf64620c7dd4ec7e72aa16ee2d5f15eb3420b92
2 files changed
+3
-3
packages/react-devtools-shared/src/backend/fiber/renderer.js
+2
-2
@@ -1078,7 +1078,7 @@ export function attach(
1078
function getComponentStack(
1079
topFrame: Error,
1080
): null | {enableOwnerStacks: boolean, componentStack: string} {
1081
- if (getCurrentFiber === undefined) {
1081
+ if (getCurrentFiber == null) {
1082
// Expected this to be part of the renderer. Ignore.
1083
return null;
1084
}
@@ -1130,7 +1130,7 @@ export function attach(
1130
type: 'error' | 'warn',
1131
args: $ReadOnlyArray<any>,
1132
): void {
1133
- if (getCurrentFiber === undefined) {
1133
+ if (getCurrentFiber == null) {
1134
// Expected this to be part of the renderer. Ignore.
1135
return;
1136
}
packages/react-devtools-shared/src/backend/types.js
+1
-1
@@ -158,7 +158,7 @@ export type ReactRenderer = {
158
currentDispatcherRef?: LegacyDispatcherRef | CurrentDispatcherRef,
159
// Only injected by React v16.9+ in DEV mode.
160
// Enables DevTools to append owners-only component stack to error messages.
161
- getCurrentFiber?: () => Fiber | null,
161
+ getCurrentFiber?: (() => Fiber | null) | null,
162
// Only injected by React Flight Clients in DEV mode.
163
// Enables DevTools to append owners-only component stack to error messages from Server Components.
164
getCurrentComponentInfo?: () => ReactComponentInfo | null,