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.

![Screenshot 2024-09-16 at 10 52
00](https://github.com/user-attachments/assets/a0c773aa-ebbf-4fd5-95c4-cac3cc0c203f)
This commit is contained in:
Ruslan Lesiutin
2024-09-16 14:47:57 +01:00
committed by GitHub
parent fc5ef50da8
commit 8cf64620c7
2 changed files with 3 additions and 3 deletions
@@ -1078,7 +1078,7 @@ export function attach(
function getComponentStack(
topFrame: Error,
): null | {enableOwnerStacks: boolean, componentStack: string} {
if (getCurrentFiber === undefined) {
if (getCurrentFiber == null) {
// Expected this to be part of the renderer. Ignore.
return null;
}
@@ -1130,7 +1130,7 @@ export function attach(
type: 'error' | 'warn',
args: $ReadOnlyArray<any>,
): void {
if (getCurrentFiber === undefined) {
if (getCurrentFiber == null) {
// Expected this to be part of the renderer. Ignore.
return;
}
+1 -1
View File
@@ -158,7 +158,7 @@ export type ReactRenderer = {
currentDispatcherRef?: LegacyDispatcherRef | CurrentDispatcherRef,
// Only injected by React v16.9+ in DEV mode.
// Enables DevTools to append owners-only component stack to error messages.
getCurrentFiber?: () => Fiber | null,
getCurrentFiber?: (() => Fiber | null) | null,
// Only injected by React Flight Clients in DEV mode.
// Enables DevTools to append owners-only component stack to error messages from Server Components.
getCurrentComponentInfo?: () => ReactComponentInfo | null,