Skip to content

Commit 0b28992

Browse files
committed
[DevTools] Record Suspense node for roots in legacy renderers
1 parent 4eecc9b commit 0b28992

File tree

9 files changed

+20
-35
lines changed

9 files changed

+20
-35
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: 15 additions & 2 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);
@@ -521,6 +528,8 @@ export function attach(
521528
// All unmounts are batched in a single message.
522529
// [TREE_OPERATION_REMOVE, removedIDLength, ...ids]
523530
(numUnmountIDs > 0 ? 2 + numUnmountIDs : 0) +
531+
// [SUSPENSE_TREE_OPERATION_REMOVE, 1, pendingUnmountedRootID]
532+
(pendingUnmountedRootID === null ? 0 : 3) +
524533
// Mount operations
525534
pendingOperations.length,
526535
);
@@ -557,6 +566,10 @@ export function attach(
557566
if (pendingUnmountedRootID !== null) {
558567
operations[i] = pendingUnmountedRootID;
559568
i++;
569+
570+
operations[i++] = SUSPENSE_TREE_OPERATION_REMOVE;
571+
operations[i++] = 1;
572+
operations[i++] = pendingUnmountedRootID;
560573
}
561574
}
562575

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) {
@@ -905,10 +896,7 @@ export default class Store extends EventEmitter<{
905896
if (root === null) {
906897
return [];
907898
}
908-
if (
909-
!this.supportsTogglingSuspense(rootID) ||
910-
!this.supportsSuspenseTree(rootID)
911-
) {
899+
if (!this.supportsTogglingSuspense(rootID)) {
912900
return [];
913901
}
914902
const list: SuspenseNode['id'][] = [];
@@ -1183,7 +1171,6 @@ export default class Store extends EventEmitter<{
11831171
let supportsStrictMode = false;
11841172
let hasOwnerMetadata = false;
11851173
let supportsTogglingSuspense = false;
1186-
let supportsSuspenseTree = false;
11871174

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

12001187
supportsTogglingSuspense = operations[i] > 0;
12011188
i++;
1202-
1203-
supportsSuspenseTree = operations[i] > 0;
1204-
i++;
12051189
}
12061190

12071191
this._roots = this._roots.concat(id);
@@ -1210,7 +1194,6 @@ export default class Store extends EventEmitter<{
12101194
supportsBasicProfiling,
12111195
hasOwnerMetadata,
12121196
supportsStrictMode,
1213-
supportsSuspenseTree,
12141197
supportsTogglingSuspense,
12151198
supportsTimeline,
12161199
});

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)