Skip to content

Commit eceb91e

Browse files
committed
Track if inside suspense or error boundary to highlight the buttons
1 parent 7cb1b52 commit eceb91e

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
@@ -4350,9 +4350,6 @@ export function attach(
43504350
const owners: null | Array<SerializedElement> =
43514351
getOwnersListFromInstance(fiberInstance);
43524352

4353-
const isTimedOutSuspense =
4354-
tag === SuspenseComponent && memoizedState !== null;
4355-
43564353
let hooks = null;
43574354
if (usesHooks) {
43584355
const originalConsoleMethods: {[string]: $FlowFixMe} = {};
@@ -4382,14 +4379,25 @@ export function attach(
43824379

43834380
let rootType = null;
43844381
let current = fiber;
4382+
let hasErrorBoundary = false;
4383+
let hasSuspenseBoundary = false;
43854384
while (current.return !== null) {
4385+
const temp = current;
43864386
current = current.return;
4387+
if (temp.tag === SuspenseComponent) {
4388+
hasSuspenseBoundary = true;
4389+
} else if (isErrorBoundary(temp)) {
4390+
hasErrorBoundary = true;
4391+
}
43874392
}
43884393
const fiberRoot = current.stateNode;
43894394
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
43904395
rootType = fiberRoot._debugRootType;
43914396
}
43924397

4398+
const isTimedOutSuspense =
4399+
tag === SuspenseComponent && memoizedState !== null;
4400+
43934401
let isErrored = false;
43944402
if (isErrorBoundary(fiber)) {
43954403
// if the current inspected element is an error boundary,
@@ -4440,12 +4448,13 @@ export function attach(
44404448
canEditFunctionPropsRenamePaths:
44414449
typeof overridePropsRenamePath === 'function',
44424450

4443-
canToggleError: supportsTogglingError,
4451+
canToggleError: supportsTogglingError && hasErrorBoundary,
44444452
// Is this error boundary in error state.
44454453
isErrored,
44464454

44474455
canToggleSuspense:
44484456
supportsTogglingSuspense &&
4457+
hasSuspenseBoundary &&
44494458
// If it's showing the real content, we can always flip fallback.
44504459
(!isTimedOutSuspense ||
44514460
// If it's showing fallback because we previously forced it to,
@@ -4506,20 +4515,24 @@ export function attach(
45064515
getOwnersListFromInstance(virtualInstance);
45074516

45084517
let rootType = null;
4509-
let parent = virtualInstance.parent;
4510-
while (parent !== null) {
4511-
if (parent.kind !== VIRTUAL_INSTANCE) {
4512-
let current = parent.data;
4513-
while (current.return !== null) {
4514-
current = current.return;
4515-
}
4516-
const fiberRoot = current.stateNode;
4517-
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
4518-
rootType = fiberRoot._debugRootType;
4518+
let hasErrorBoundary = false;
4519+
let hasSuspenseBoundary = false;
4520+
const nearestFiber = getNearestFiber(virtualInstance);
4521+
if (nearestFiber !== null) {
4522+
let current = nearestFiber;
4523+
while (current.return !== null) {
4524+
const temp = current;
4525+
current = current.return;
4526+
if (temp.tag === SuspenseComponent) {
4527+
hasSuspenseBoundary = true;
4528+
} else if (isErrorBoundary(temp)) {
4529+
hasErrorBoundary = true;
45194530
}
4520-
break;
45214531
}
4522-
parent = parent.parent;
4532+
const fiberRoot = current.stateNode;
4533+
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
4534+
rootType = fiberRoot._debugRootType;
4535+
}
45234536
}
45244537

45254538
const plugins: Plugins = {
@@ -4537,10 +4550,10 @@ export function attach(
45374550
canEditFunctionPropsDeletePaths: false,
45384551
canEditFunctionPropsRenamePaths: false,
45394552

4540-
canToggleError: supportsTogglingError,
4553+
canToggleError: supportsTogglingError && hasErrorBoundary,
45414554
isErrored: false,
45424555

4543-
canToggleSuspense: supportsTogglingSuspense,
4556+
canToggleSuspense: supportsTogglingSuspense && hasSuspenseBoundary,
45444557

45454558
// Can view component source location.
45464559
canViewSource,

0 commit comments

Comments
 (0)