Skip to content

Commit d94b3cf

Browse files
committed
[DevTools] Record Suspense node for roots in legacy renderers
1 parent ae0dc78 commit d94b3cf

File tree

9 files changed

+26
-36
lines changed

9 files changed

+26
-36
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@ export function attach(
10651065
scheduleUpdate,
10661066
getCurrentFiber,
10671067
} = renderer;
1068-
const supportsSuspenseTree = true;
10691068
const supportsTogglingError =
10701069
typeof setErrorHandler === 'function' &&
10711070
typeof scheduleUpdate === 'function';
@@ -2395,7 +2394,6 @@ export function attach(
23952394
);
23962395
pushOperation(hasOwnerMetadata ? 1 : 0);
23972396
pushOperation(supportsTogglingSuspense ? 1 : 0);
2398-
pushOperation(supportsSuspenseTree ? 1 : 0);
23992397
24002398
if (isProfiling) {
24012399
if (displayNamesByRootID !== null) {

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
TREE_OPERATION_ADD,
3535
TREE_OPERATION_REMOVE,
3636
TREE_OPERATION_REORDER_CHILDREN,
37+
SUSPENSE_TREE_OPERATION_ADD,
38+
SUSPENSE_TREE_OPERATION_REMOVE,
3739
UNKNOWN_SUSPENDERS_NONE,
3840
} from '../../constants';
3941
import {decorateMany, forceUpdate, restoreMany} from './utils';
@@ -181,7 +183,6 @@ export function attach(
181183
}
182184

183185
const supportsTogglingSuspense = false;
184-
const supportsSuspenseTree = false;
185186

186187
function getDisplayNameForElementID(id: number): string | null {
187188
const internalInstance = idToInternalInstanceMap.get(id);
@@ -412,7 +413,13 @@ export function attach(
412413
pushOperation(0); // StrictMode supported?
413414
pushOperation(hasOwnerMetadata ? 1 : 0);
414415
pushOperation(supportsTogglingSuspense ? 1 : 0);
415-
pushOperation(supportsSuspenseTree ? 1 : 0);
416+
417+
pushOperation(SUSPENSE_TREE_OPERATION_ADD);
418+
pushOperation(id);
419+
pushOperation(parentID);
420+
pushOperation(getStringID(null)); // name
421+
// TODO: Measure rect of root
422+
pushOperation(-1);
416423
} else {
417424
const type = getElementType(internalInstance);
418425
const {displayName, key} = getData(internalInstance);
@@ -451,7 +458,12 @@ export function attach(
451458
}
452459

453460
function recordUnmount(internalInstance: InternalInstance, id: number) {
454-
pendingUnmountedIDs.push(id);
461+
const isRoot = parentIDStack.length === 0;
462+
if (isRoot) {
463+
pendingUnmountedRootID = id;
464+
} else {
465+
pendingUnmountedIDs.push(id);
466+
}
455467
idToInternalInstanceMap.delete(id);
456468
}
457469

@@ -521,6 +533,8 @@ export function attach(
521533
// All unmounts are batched in a single message.
522534
// [TREE_OPERATION_REMOVE, removedIDLength, ...ids]
523535
(numUnmountIDs > 0 ? 2 + numUnmountIDs : 0) +
536+
// [SUSPENSE_TREE_OPERATION_REMOVE, 1, pendingUnmountedRootID]
537+
(pendingUnmountedRootID === null ? 0 : 3) +
524538
// Mount operations
525539
pendingOperations.length,
526540
);
@@ -557,6 +571,10 @@ export function attach(
557571
if (pendingUnmountedRootID !== null) {
558572
operations[i] = pendingUnmountedRootID;
559573
i++;
574+
575+
operations[i++] = SUSPENSE_TREE_OPERATION_REMOVE;
576+
operations[i++] = 1;
577+
operations[i++] = pendingUnmountedRootID;
560578
}
561579
}
562580

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export type Capabilities = {
9090
supportsBasicProfiling: boolean,
9191
hasOwnerMetadata: boolean,
9292
supportsStrictMode: boolean,
93-
supportsSuspenseTree: boolean,
9493
supportsTogglingSuspense: boolean,
9594
supportsTimeline: boolean,
9695
};
@@ -494,14 +493,6 @@ export default class Store extends EventEmitter<{
494493
);
495494
}
496495

497-
supportsSuspenseTree(rootID: Element['id']): boolean {
498-
const capabilities = this._rootIDToCapabilities.get(rootID);
499-
if (capabilities === undefined) {
500-
throw new Error(`No capabilities registered for root ${rootID}`);
501-
}
502-
return capabilities.supportsSuspenseTree;
503-
}
504-
505496
supportsTogglingSuspense(rootID: Element['id']): boolean {
506497
const capabilities = this._rootIDToCapabilities.get(rootID);
507498
if (capabilities === undefined) {
@@ -904,10 +895,7 @@ export default class Store extends EventEmitter<{
904895
if (root === null) {
905896
return [];
906897
}
907-
if (
908-
!this.supportsTogglingSuspense(rootID) ||
909-
!this.supportsSuspenseTree(rootID)
910-
) {
898+
if (!this.supportsTogglingSuspense(rootID)) {
911899
return [];
912900
}
913901
const list: SuspenseNode['id'][] = [];
@@ -1182,7 +1170,6 @@ export default class Store extends EventEmitter<{
11821170
let supportsStrictMode = false;
11831171
let hasOwnerMetadata = false;
11841172
let supportsTogglingSuspense = false;
1185-
let supportsSuspenseTree = false;
11861173

11871174
// If we don't know the bridge protocol, guess that we're dealing with the latest.
11881175
// If we do know it, we can take it into consideration when parsing operations.
@@ -1198,9 +1185,6 @@ export default class Store extends EventEmitter<{
11981185

11991186
supportsTogglingSuspense = operations[i] > 0;
12001187
i++;
1201-
1202-
supportsSuspenseTree = operations[i] > 0;
1203-
i++;
12041188
}
12051189

12061190
this._roots = this._roots.concat(id);
@@ -1209,7 +1193,6 @@ export default class Store extends EventEmitter<{
12091193
supportsBasicProfiling,
12101194
hasOwnerMetadata,
12111195
supportsStrictMode,
1212-
supportsSuspenseTree,
12131196
supportsTogglingSuspense,
12141197
supportsTimeline,
12151198
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function printStore(
176176

177177
rootWeight += weight;
178178

179-
if (includeSuspense && store.supportsSuspenseTree(rootID)) {
179+
if (includeSuspense) {
180180
const root = store.getSuspenseByID(rootID);
181181
// Roots from legacy renderers don't have a separate Suspense tree
182182
if (root !== null) {

packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ function updateTree(
210210
i++; // supportsStrictMode flag
211211
i++; // hasOwnerMetadata flag
212212
i++; // supportsTogglingSuspense flag
213-
i++; // supportsSuspenseTree flag
214213

215214
if (__DEBUG__) {
216215
debug('Add', `new root fiber ${id}`);

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseRects.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ function getDocumentBoundingRect(
190190

191191
for (let i = 0; i < roots.length; i++) {
192192
const rootID = roots[i];
193-
const root = store.supportsSuspenseTree(rootID)
194-
? store.getSuspenseByID(rootID)
195-
: null;
193+
const root = store.getSuspenseByID(rootID);
196194
if (root === null) {
197195
continue;
198196
}

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseTimeline.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,7 @@ export default function SuspenseTimeline(): React$Node {
243243
const name = '#' + rootID;
244244
// TODO: Highlight host on hover
245245
return (
246-
<option
247-
key={rootID}
248-
value={rootID}
249-
disabled={!store.supportsSuspenseTree(rootID)}>
246+
<option key={rootID} value={rootID}>
250247
{name}
251248
</option>
252249
);

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseTreeContext.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ type Props = {
8282

8383
function getDefaultRootID(store: Store): Element['id'] | null {
8484
const designatedRootID = store.roots.find(rootID => {
85-
const suspense = store.supportsSuspenseTree(rootID)
86-
? store.getSuspenseByID(rootID)
87-
: null;
85+
const suspense = store.getSuspenseByID(rootID);
8886
return (
8987
store.supportsTogglingSuspense(rootID) &&
9088
suspense !== null &&

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ export function printOperationsArray(operations: Array<number>) {
263263
i++; // supportsStrictMode
264264
i++; // hasOwnerMetadata
265265
i++; // supportsTogglingSuspense
266-
i++; // supportsSuspenseTree
267266
} else {
268267
const parentID = ((operations[i]: any): number);
269268
i++;

0 commit comments

Comments
 (0)