Skip to content

Commit a41d037

Browse files
committed
Rename SSR warning variables to be more descriptive what they stand for
1 parent 172a0c5 commit a41d037

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ let getNodeSignatureForMessage = (node: Node) => '<...>';
7272
let getTagWithPropsSignature = (tag: string, props: Object) => '<...>';
7373
let getNodeSurroundingsAndDiff = (
7474
parentNode: Element | Document,
75-
deletedIndex: number,
76-
insertedIndex: number,
75+
hostInstanceDeletedIndex: number,
76+
hostInstanceInsertedIndex: number,
7777
insertTag: string | null,
7878
insertProps: Object | null,
7979
insertText: string | null,
@@ -254,8 +254,8 @@ if (__DEV__) {
254254

255255
getNodeSurroundingsAndDiff = function(
256256
parentNode: Element | Document,
257-
deletedIndex: number,
258-
insertedIndex: number,
257+
hostInstanceDeletedIndex: number,
258+
hostInstanceInsertedIndex: number,
259259
insertTag: string | null,
260260
insertProps: Object | null,
261261
insertText: string | null,
@@ -298,12 +298,12 @@ if (__DEV__) {
298298
++hydrationSkippedCount;
299299
continue;
300300
}
301-
if (i - hydrationSkippedCount === deletedIndex) {
301+
if (i - hydrationSkippedCount === hostInstanceDeletedIndex) {
302302
ret += DIFF_REMOVED + INDENT + getNodeSignatureForDiff(node);
303303
} else {
304304
ret += DIFF_UNCHANGED + INDENT + getNodeSignatureForDiff(node);
305305
}
306-
if (i - hydrationSkippedCount === insertedIndex) {
306+
if (i - hydrationSkippedCount === hostInstanceInsertedIndex) {
307307
insert();
308308
}
309309
}
@@ -1447,8 +1447,8 @@ export function warnForInsertedHydratedElement(
14471447
parentNode: Element | Document,
14481448
tag: string,
14491449
props: Object,
1450-
index: number,
1451-
isReplaced: boolean,
1450+
hydrationWarningHostInstanceIndex: number,
1451+
hydrationWarningHostInstanceIsReplaced: boolean,
14521452
) {
14531453
if (__DEV__) {
14541454
if (didWarnInvalidHydration) {
@@ -1462,8 +1462,10 @@ export function warnForInsertedHydratedElement(
14621462
getNodeSignatureForMessage(parentNode),
14631463
getNodeSurroundingsAndDiff(
14641464
parentNode,
1465-
isReplaced ? index : -1,
1466-
index,
1465+
hydrationWarningHostInstanceIsReplaced
1466+
? hydrationWarningHostInstanceIndex
1467+
: -1,
1468+
hydrationWarningHostInstanceIndex,
14671469
tag,
14681470
props,
14691471
null,
@@ -1475,8 +1477,8 @@ export function warnForInsertedHydratedElement(
14751477
export function warnForInsertedHydratedText(
14761478
parentNode: Element | Document,
14771479
text: string,
1478-
index: number,
1479-
isReplaced: boolean,
1480+
hydrationWarningHostInstanceIndex: number,
1481+
hydrationWarningHostInstanceIsReplaced: boolean,
14801482
) {
14811483
if (__DEV__) {
14821484
if (text === '') {
@@ -1497,8 +1499,10 @@ export function warnForInsertedHydratedText(
14971499
getNodeSignatureForMessage(parentNode),
14981500
getNodeSurroundingsAndDiff(
14991501
parentNode,
1500-
isReplaced ? index : -1,
1501-
index,
1502+
hydrationWarningHostInstanceIsReplaced
1503+
? hydrationWarningHostInstanceIndex
1504+
: -1,
1505+
hydrationWarningHostInstanceIndex,
15021506
null,
15031507
null,
15041508
text,

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -558,28 +558,33 @@ export function didNotFindHydratableContainerInstance(
558558
parentContainer: Container,
559559
type: string,
560560
props: Props,
561-
index: number,
562-
isReplaced: boolean,
561+
hydrationWarningHostInstanceIndex: number,
562+
hydrationWarningHostInstanceIsReplaced: boolean,
563563
) {
564564
if (__DEV__) {
565565
warnForInsertedHydratedElement(
566566
parentContainer,
567567
type,
568568
props,
569-
index,
570-
isReplaced,
569+
hydrationWarningHostInstanceIndex,
570+
hydrationWarningHostInstanceIsReplaced,
571571
);
572572
}
573573
}
574574

575575
export function didNotFindHydratableContainerTextInstance(
576576
parentContainer: Container,
577577
text: string,
578-
index: number,
579-
isReplaced: boolean,
578+
hydrationWarningHostInstanceIndex: number,
579+
hydrationWarningHostInstanceIsReplaced: boolean,
580580
) {
581581
if (__DEV__) {
582-
warnForInsertedHydratedText(parentContainer, text, index, isReplaced);
582+
warnForInsertedHydratedText(
583+
parentContainer,
584+
text,
585+
hydrationWarningHostInstanceIndex,
586+
hydrationWarningHostInstanceIsReplaced,
587+
);
583588
}
584589
}
585590

@@ -589,16 +594,16 @@ export function didNotFindHydratableInstance(
589594
parentInstance: Instance,
590595
type: string,
591596
props: Props,
592-
index: number,
593-
isReplaced: boolean,
597+
hydrationWarningHostInstanceIndex: number,
598+
hydrationWarningHostInstanceIsReplaced: boolean,
594599
) {
595600
if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
596601
warnForInsertedHydratedElement(
597602
parentInstance,
598603
type,
599604
props,
600-
index,
601-
isReplaced,
605+
hydrationWarningHostInstanceIndex,
606+
hydrationWarningHostInstanceIsReplaced,
602607
);
603608
}
604609
}
@@ -608,10 +613,15 @@ export function didNotFindHydratableTextInstance(
608613
parentProps: Props,
609614
parentInstance: Instance,
610615
text: string,
611-
index: number,
612-
isReplaced: boolean,
616+
hydrationWarningHostInstanceIndex: number,
617+
hydrationWarningHostInstanceIsReplaced: boolean,
613618
) {
614619
if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
615-
warnForInsertedHydratedText(parentInstance, text, index, isReplaced);
620+
warnForInsertedHydratedText(
621+
parentInstance,
622+
text,
623+
hydrationWarningHostInstanceIndex,
624+
hydrationWarningHostInstanceIsReplaced,
625+
);
616626
}
617627
}

packages/react-reconciler/src/ReactFiberHydrationContext.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ function deleteHydratableInstance(
102102
function insertNonHydratedInstance(
103103
returnFiber: Fiber,
104104
fiber: Fiber,
105-
isReplaced: boolean,
105+
hydrationWarningHostInstanceIsReplaced: boolean,
106106
) {
107107
fiber.effectTag |= Placement;
108108
if (__DEV__) {
109+
// TODO: Find out what `hydrationWarningHostInstanceIndex` should be, `fiber.index` is wrong.
110+
const hydrationWarningHostInstanceIndex = fiber.index;
109111
switch (returnFiber.tag) {
110112
case HostRoot: {
111113
const parentContainer = returnFiber.stateNode.containerInfo;
@@ -117,17 +119,17 @@ function insertNonHydratedInstance(
117119
parentContainer,
118120
type,
119121
props,
120-
fiber.index,
121-
isReplaced,
122+
hydrationWarningHostInstanceIndex,
123+
hydrationWarningHostInstanceIsReplaced,
122124
);
123125
break;
124126
case HostText:
125127
const text = fiber.pendingProps;
126128
didNotFindHydratableContainerTextInstance(
127129
parentContainer,
128130
text,
129-
fiber.index,
130-
isReplaced,
131+
hydrationWarningHostInstanceIndex,
132+
hydrationWarningHostInstanceIsReplaced,
131133
);
132134
break;
133135
}
@@ -147,8 +149,8 @@ function insertNonHydratedInstance(
147149
parentInstance,
148150
type,
149151
props,
150-
fiber.index,
151-
isReplaced,
152+
hydrationWarningHostInstanceIndex,
153+
hydrationWarningHostInstanceIsReplaced,
152154
);
153155
break;
154156
case HostText:
@@ -158,8 +160,8 @@ function insertNonHydratedInstance(
158160
parentProps,
159161
parentInstance,
160162
text,
161-
fiber.index,
162-
isReplaced,
163+
hydrationWarningHostInstanceIndex,
164+
hydrationWarningHostInstanceIsReplaced,
163165
);
164166
break;
165167
}

0 commit comments

Comments
 (0)