Skip to content

Commit

Permalink
fix[rdt/fiber/renderer.js]: getCurrentFiber can be injected as null (#…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
hoxyq authored Sep 16, 2024
1 parent fc5ef50 commit 8cf6462
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8cf6462

Please sign in to comment.