Skip to content

Commit c7221da

Browse files
committed
Track if inside suspense or error boundary to highlight the buttons
1 parent 66b5559 commit c7221da

File tree

1 file changed

+31
-18
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+31
-18
lines changed

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

+31-18
Original file line numberDiff line numberDiff line change
@@ -4356,9 +4356,6 @@ export function attach(
43564356
const owners: null | Array<SerializedElement> =
43574357
getOwnersListFromInstance(fiberInstance);
43584358

4359-
const isTimedOutSuspense =
4360-
tag === SuspenseComponent && memoizedState !== null;
4361-
43624359
let hooks = null;
43634360
if (usesHooks) {
43644361
const originalConsoleMethods: {[string]: $FlowFixMe} = {};
@@ -4388,14 +4385,25 @@ export function attach(
43884385

43894386
let rootType = null;
43904387
let current = fiber;
4388+
let hasErrorBoundary = false;
4389+
let hasSuspenseBoundary = false;
43914390
while (current.return !== null) {
4391+
const temp = current;
43924392
current = current.return;
4393+
if (temp.tag === SuspenseComponent) {
4394+
hasSuspenseBoundary = true;
4395+
} else if (isErrorBoundary(temp)) {
4396+
hasErrorBoundary = true;
4397+
}
43934398
}
43944399
const fiberRoot = current.stateNode;
43954400
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
43964401
rootType = fiberRoot._debugRootType;
43974402
}
43984403

4404+
const isTimedOutSuspense =
4405+
tag === SuspenseComponent && memoizedState !== null;
4406+
43994407
let isErrored = false;
44004408
if (isErrorBoundary(fiber)) {
44014409
// if the current inspected element is an error boundary,
@@ -4446,12 +4454,13 @@ export function attach(
44464454
canEditFunctionPropsRenamePaths:
44474455
typeof overridePropsRenamePath === 'function',
44484456

4449-
canToggleError: supportsTogglingError,
4457+
canToggleError: supportsTogglingError && hasErrorBoundary,
44504458
// Is this error boundary in error state.
44514459
isErrored,
44524460

44534461
canToggleSuspense:
44544462
supportsTogglingSuspense &&
4463+
hasSuspenseBoundary &&
44554464
// If it's showing the real content, we can always flip fallback.
44564465
(!isTimedOutSuspense ||
44574466
// If it's showing fallback because we previously forced it to,
@@ -4512,20 +4521,24 @@ export function attach(
45124521
getOwnersListFromInstance(virtualInstance);
45134522

45144523
let rootType = null;
4515-
let parent = virtualInstance.parent;
4516-
while (parent !== null) {
4517-
if (parent.kind !== VIRTUAL_INSTANCE) {
4518-
let current = parent.data;
4519-
while (current.return !== null) {
4520-
current = current.return;
4521-
}
4522-
const fiberRoot = current.stateNode;
4523-
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
4524-
rootType = fiberRoot._debugRootType;
4524+
let hasErrorBoundary = false;
4525+
let hasSuspenseBoundary = false;
4526+
const nearestFiber = getNearestFiber(virtualInstance);
4527+
if (nearestFiber !== null) {
4528+
let current = nearestFiber;
4529+
while (current.return !== null) {
4530+
const temp = current;
4531+
current = current.return;
4532+
if (temp.tag === SuspenseComponent) {
4533+
hasSuspenseBoundary = true;
4534+
} else if (isErrorBoundary(temp)) {
4535+
hasErrorBoundary = true;
45254536
}
4526-
break;
45274537
}
4528-
parent = parent.parent;
4538+
const fiberRoot = current.stateNode;
4539+
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
4540+
rootType = fiberRoot._debugRootType;
4541+
}
45294542
}
45304543

45314544
const plugins: Plugins = {
@@ -4543,10 +4556,10 @@ export function attach(
45434556
canEditFunctionPropsDeletePaths: false,
45444557
canEditFunctionPropsRenamePaths: false,
45454558

4546-
canToggleError: supportsTogglingError,
4559+
canToggleError: supportsTogglingError && hasErrorBoundary,
45474560
isErrored: false,
45484561

4549-
canToggleSuspense: supportsTogglingSuspense,
4562+
canToggleSuspense: supportsTogglingSuspense && hasSuspenseBoundary,
45504563

45514564
// Can view component source location.
45524565
canViewSource,

0 commit comments

Comments
 (0)