Skip to content

Commit 2d98b45

Browse files
authored
[DevTools] Fix Suspense boundaries always being marked as not suspended (facebook#34206)
1 parent 2ba7b07 commit 2d98b45

File tree

7 files changed

+17
-4
lines changed

7 files changed

+17
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,6 +6071,11 @@ export function attach(
60716071
nativeTag = getNativeTag(fiber.stateNode);
60726072
}
60736073
6074+
let isSuspended: boolean | null = null;
6075+
if (tag === SuspenseComponent) {
6076+
isSuspended = memoizedState !== null;
6077+
}
6078+
60746079
const suspendedBy =
60756080
fiberInstance.suspenseNode !== null
60766081
? // If this is a Suspense boundary, then we include everything in the subtree that might suspend
@@ -6121,6 +6126,7 @@ export function attach(
61216126
forceFallbackForFibers.has(fiber) ||
61226127
(fiber.alternate !== null &&
61236128
forceFallbackForFibers.has(fiber.alternate))),
6129+
isSuspended: isSuspended,
61246130
61256131
source,
61266132
@@ -6209,6 +6215,7 @@ export function attach(
62096215
const componentLogsEntry =
62106216
componentInfoToComponentLogsMap.get(componentInfo);
62116217
6218+
const isSuspended = null;
62126219
// Things that Suspended this Server Component (use(), awaits and direct child promises)
62136220
const suspendedBy = virtualInstance.suspendedBy;
62146221
const suspendedByRange = getSuspendedByRange(
@@ -6230,6 +6237,7 @@ export function attach(
62306237
isErrored: false,
62316238
62326239
canToggleSuspense: supportsTogglingSuspense && hasSuspenseBoundary,
6240+
isSuspended: isSuspended,
62336241
62346242
source,
62356243

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ export function attach(
836836

837837
// Suspense did not exist in legacy versions
838838
canToggleSuspense: false,
839+
isSuspended: null,
839840

840841
source: null,
841842

packages/react-devtools-shared/src/backend/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export type InspectedElement = {
285285

286286
// Is this Suspense, and can its value be overridden now?
287287
canToggleSuspense: boolean,
288+
// If this Element is suspended. Currently only set on Suspense boundaries.
289+
isSuspended: boolean | null,
288290

289291
// Does the component have legacy context attached to it.
290292
hasLegacyContext: boolean,

packages/react-devtools-shared/src/backendAPI.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export function convertInspectedElementBackendToFrontend(
251251
canToggleError,
252252
isErrored,
253253
canToggleSuspense,
254+
isSuspended,
254255
hasLegacyContext,
255256
id,
256257
type,
@@ -287,6 +288,7 @@ export function convertInspectedElementBackendToFrontend(
287288
canToggleError,
288289
isErrored,
289290
canToggleSuspense,
291+
isSuspended,
290292
hasLegacyContext,
291293
id,
292294
key,

packages/react-devtools-shared/src/devtools/views/Components/InspectedElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default function InspectedElementWrapper(_: Props): React.Node {
113113
element !== null &&
114114
element.type === ElementTypeSuspense &&
115115
inspectedElement != null &&
116-
inspectedElement.state != null;
116+
inspectedElement.isSuspended;
117117

118118
const canToggleError =
119119
!hideToggleErrorAction &&

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspenseToggle.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ export default function InspectedElementSuspenseToggle({
3030
}: Props): React.Node {
3131
const {readOnly} = React.useContext(OptionsContext);
3232

33-
const {id, state, type} = inspectedElement;
33+
const {id, isSuspended, type} = inspectedElement;
3434
const canToggleSuspense = !readOnly && inspectedElement.canToggleSuspense;
3535

3636
if (type !== ElementTypeSuspense) {
3737
return null;
3838
}
3939

40-
const isSuspended = state !== null;
41-
4240
const toggleSuspense = (path: any, value: boolean) => {
4341
const rendererID = store.getRendererIDForElement(id);
4442
if (rendererID !== null) {

packages/react-devtools-shared/src/frontend/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ export type InspectedElement = {
264264

265265
// Is this Suspense, and can its value be overridden now?
266266
canToggleSuspense: boolean,
267+
// If this Element is suspended. Currently only set on Suspense boundaries.
268+
isSuspended: boolean | null,
267269

268270
// Does the component have legacy context attached to it.
269271
hasLegacyContext: boolean,

0 commit comments

Comments
 (0)