Skip to content

Commit aef8134

Browse files
committed
Differentiate SuspenseInstance vs ActivityInstance comment node
So we can warn for mismatching Suspense vs Activity.
1 parent 938521a commit aef8134

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,10 +3042,10 @@ export function canHydrateTextInstance(
30423042
return ((instance: any): TextInstance);
30433043
}
30443044
3045-
function canHydrateHydrationBoundary<T: SuspenseInstance | ActivityInstance>(
3045+
function canHydrateHydrationBoundary(
30463046
instance: HydratableInstance,
30473047
inRootOrSingleton: boolean,
3048-
): null | T {
3048+
): null | SuspenseInstance | ActivityInstance {
30493049
while (instance.nodeType !== COMMENT_NODE) {
30503050
if (!inRootOrSingleton) {
30513051
return null;
@@ -3056,24 +3056,42 @@ function canHydrateHydrationBoundary<T: SuspenseInstance | ActivityInstance>(
30563056
}
30573057
instance = nextInstance;
30583058
}
3059-
// This has now been refined to a suspense node.
3060-
return ((instance: any): T);
3059+
// This has now been refined to a hydration boundary node.
3060+
return (instance: any);
30613061
}
30623062
30633063
export function canHydrateActivityInstance(
30643064
instance: HydratableInstance,
30653065
inRootOrSingleton: boolean,
30663066
): null | ActivityInstance {
3067-
// $FlowFixMe: This should be inferred. I can't pass explicit since it breaks build tooling.
3068-
return canHydrateHydrationBoundary(instance, inRootOrSingleton);
3067+
const hydratableInstance = canHydrateHydrationBoundary(
3068+
instance,
3069+
inRootOrSingleton,
3070+
);
3071+
if (
3072+
hydratableInstance !== null &&
3073+
hydratableInstance.data === ACTIVITY_START_DATA
3074+
) {
3075+
return (hydratableInstance: any);
3076+
}
3077+
return null;
30693078
}
30703079
30713080
export function canHydrateSuspenseInstance(
30723081
instance: HydratableInstance,
30733082
inRootOrSingleton: boolean,
30743083
): null | SuspenseInstance {
3075-
// $FlowFixMe: This should be inferred. I can't pass explicit since it breaks build tooling.
3076-
return canHydrateHydrationBoundary(instance, inRootOrSingleton);
3084+
const hydratableInstance = canHydrateHydrationBoundary(
3085+
instance,
3086+
inRootOrSingleton,
3087+
);
3088+
if (
3089+
hydratableInstance !== null &&
3090+
hydratableInstance.data !== ACTIVITY_START_DATA
3091+
) {
3092+
return (hydratableInstance: any);
3093+
}
3094+
return null;
30773095
}
30783096
30793097
export function isSuspenseInstancePending(instance: SuspenseInstance): boolean {
@@ -3299,6 +3317,12 @@ export function describeHydratableInstanceForDevWarnings(
32993317
props: getPropsFromElement((instance: any)),
33003318
};
33013319
} else if (instance.nodeType === COMMENT_NODE) {
3320+
if (instance.data === ACTIVITY_START_DATA) {
3321+
return {
3322+
type: 'Activity',
3323+
props: {},
3324+
};
3325+
}
33023326
return {
33033327
type: 'Suspense',
33043328
props: {},

packages/react-reconciler/src/ReactFiberHydrationDiffs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
HostHoistable,
1515
HostSingleton,
1616
LazyComponent,
17+
ActivityComponent,
1718
SuspenseComponent,
1819
SuspenseListComponent,
1920
FunctionComponent,
@@ -83,6 +84,8 @@ function describeFiberType(fiber: Fiber): null | string {
8384
return fiber.type;
8485
case LazyComponent:
8586
return 'Lazy';
87+
case ActivityComponent:
88+
return 'Activity';
8689
case SuspenseComponent:
8790
return 'Suspense';
8891
case SuspenseListComponent:

0 commit comments

Comments
 (0)