Skip to content

Commit 03a96c7

Browse files
authored
[DevTools] Record Suspense node for roots in legacy renderers (facebook#34516)
1 parent 755ceba commit 03a96c7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 21 additions & 1 deletion
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';
@@ -411,6 +413,13 @@ export function attach(
411413
pushOperation(0); // StrictMode supported?
412414
pushOperation(hasOwnerMetadata ? 1 : 0);
413415
pushOperation(supportsTogglingSuspense ? 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);
414423
} else {
415424
const type = getElementType(internalInstance);
416425
const {displayName, key} = getData(internalInstance);
@@ -449,7 +458,12 @@ export function attach(
449458
}
450459

451460
function recordUnmount(internalInstance: InternalInstance, id: number) {
452-
pendingUnmountedIDs.push(id);
461+
const isRoot = parentIDStack.length === 0;
462+
if (isRoot) {
463+
pendingUnmountedRootID = id;
464+
} else {
465+
pendingUnmountedIDs.push(id);
466+
}
453467
idToInternalInstanceMap.delete(id);
454468
}
455469

@@ -519,6 +533,8 @@ export function attach(
519533
// All unmounts are batched in a single message.
520534
// [TREE_OPERATION_REMOVE, removedIDLength, ...ids]
521535
(numUnmountIDs > 0 ? 2 + numUnmountIDs : 0) +
536+
// [SUSPENSE_TREE_OPERATION_REMOVE, 1, pendingUnmountedRootID]
537+
(pendingUnmountedRootID === null ? 0 : 3) +
522538
// Mount operations
523539
pendingOperations.length,
524540
);
@@ -555,6 +571,10 @@ export function attach(
555571
if (pendingUnmountedRootID !== null) {
556572
operations[i] = pendingUnmountedRootID;
557573
i++;
574+
575+
operations[i++] = SUSPENSE_TREE_OPERATION_REMOVE;
576+
operations[i++] = 1;
577+
operations[i++] = pendingUnmountedRootID;
558578
}
559579
}
560580

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,11 @@ export default class Store extends EventEmitter<{
895895
if (root === null) {
896896
return [];
897897
}
898-
if (!this.supportsTogglingSuspense(root.id)) {
898+
if (!this.supportsTogglingSuspense(rootID)) {
899899
return [];
900900
}
901901
const list: SuspenseNode['id'][] = [];
902-
const suspense = this.getSuspenseByID(root.id);
902+
const suspense = this.getSuspenseByID(rootID);
903903
if (suspense !== null) {
904904
const stack = [suspense];
905905
while (stack.length > 0) {

0 commit comments

Comments
 (0)