@@ -2886,9 +2886,16 @@ export function attach(
2886
2886
previousSuspendedBy: null | Array<ReactAsyncInfo>,
2887
2887
parentSuspenseNode: null | SuspenseNode,
2888
2888
): void {
2889
- // Remove any async info from the parent, if they were in the previous set but
2889
+ // Remove any async info if they were in the previous set but
2890
2890
// is no longer in the new set.
2891
- if (previousSuspendedBy !== null && parentSuspenseNode !== null) {
2891
+ // If we just reconciled a SuspenseNode, we need to remove from that node instead of the parent.
2892
+ // This is different from inserting because inserting is done during reconiliation
2893
+ // whereas removal is done after we're done reconciling.
2894
+ const suspenseNode =
2895
+ instance.suspenseNode === null
2896
+ ? parentSuspenseNode
2897
+ : instance.suspenseNode;
2898
+ if (previousSuspendedBy !== null && suspenseNode !== null) {
2892
2899
const nextSuspendedBy = instance.suspendedBy;
2893
2900
for (let i = 0; i < previousSuspendedBy.length; i++) {
2894
2901
const asyncInfo = previousSuspendedBy[i];
@@ -2901,7 +2908,7 @@ export function attach(
2901
2908
// This IO entry is no longer blocking the current tree.
2902
2909
// Let's remove it from the parent SuspenseNode.
2903
2910
const ioInfo = asyncInfo.awaited;
2904
- const suspendedBySet = parentSuspenseNode .suspendedBy.get(ioInfo);
2911
+ const suspendedBySet = suspenseNode .suspendedBy.get(ioInfo);
2905
2912
2906
2913
if (
2907
2914
suspendedBySet === undefined ||
@@ -2928,16 +2935,16 @@ export function attach(
2928
2935
}
2929
2936
}
2930
2937
if (suspendedBySet !== undefined && suspendedBySet.size === 0) {
2931
- parentSuspenseNode .suspendedBy.delete(asyncInfo.awaited);
2938
+ suspenseNode .suspendedBy.delete(asyncInfo.awaited);
2932
2939
}
2933
2940
if (
2934
- parentSuspenseNode .hasUniqueSuspenders &&
2935
- !ioExistsInSuspenseAncestor(parentSuspenseNode , ioInfo)
2941
+ suspenseNode .hasUniqueSuspenders &&
2942
+ !ioExistsInSuspenseAncestor(suspenseNode , ioInfo)
2936
2943
) {
2937
2944
// This entry wasn't in any ancestor and is no longer in this suspense boundary.
2938
2945
// This means that a child might now be the unique suspender for this IO.
2939
2946
// Search the child boundaries to see if we can reveal any of them.
2940
- unblockSuspendedBy(parentSuspenseNode , ioInfo);
2947
+ unblockSuspendedBy(suspenseNode , ioInfo);
2941
2948
}
2942
2949
}
2943
2950
}
0 commit comments