Skip to content

Commit 0ecbbe1

Browse files
authoredOct 4, 2021
Sync hydrate discrete events in capture phase and dont replay discrete events (#22448)
1 parent a4bc8ae commit 0ecbbe1

15 files changed

+402
-102
lines changed
 

Diff for: ‎packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

+80-13
Original file line numberDiff line numberDiff line change
@@ -1905,10 +1905,19 @@ describe('ReactDOMServerPartialHydration', () => {
19051905
resolve();
19061906
await promise;
19071907
});
1908-
expect(clicks).toBe(1);
1909-
1910-
expect(container.textContent).toBe('Hello');
19111908

1909+
if (
1910+
gate(
1911+
flags =>
1912+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
1913+
)
1914+
) {
1915+
expect(clicks).toBe(0);
1916+
expect(container.textContent).toBe('Click meHello');
1917+
} else {
1918+
expect(clicks).toBe(1);
1919+
expect(container.textContent).toBe('Hello');
1920+
}
19121921
document.body.removeChild(container);
19131922
});
19141923

@@ -1991,7 +2000,16 @@ describe('ReactDOMServerPartialHydration', () => {
19912000
await promise;
19922001
});
19932002

1994-
expect(onEvent).toHaveBeenCalledTimes(2);
2003+
if (
2004+
gate(
2005+
flags =>
2006+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2007+
)
2008+
) {
2009+
expect(onEvent).toHaveBeenCalledTimes(0);
2010+
} else {
2011+
expect(onEvent).toHaveBeenCalledTimes(2);
2012+
}
19952013

19962014
document.body.removeChild(container);
19972015
});
@@ -2072,7 +2090,17 @@ describe('ReactDOMServerPartialHydration', () => {
20722090
resolve();
20732091
await promise;
20742092
});
2075-
expect(clicks).toBe(2);
2093+
2094+
if (
2095+
gate(
2096+
flags =>
2097+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2098+
)
2099+
) {
2100+
expect(clicks).toBe(0);
2101+
} else {
2102+
expect(clicks).toBe(2);
2103+
}
20762104

20772105
document.body.removeChild(container);
20782106
});
@@ -2158,7 +2186,16 @@ describe('ReactDOMServerPartialHydration', () => {
21582186
resolve();
21592187
await promise;
21602188
});
2161-
expect(onEvent).toHaveBeenCalledTimes(2);
2189+
if (
2190+
gate(
2191+
flags =>
2192+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2193+
)
2194+
) {
2195+
expect(onEvent).toHaveBeenCalledTimes(0);
2196+
} else {
2197+
expect(onEvent).toHaveBeenCalledTimes(2);
2198+
}
21622199

21632200
document.body.removeChild(container);
21642201
});
@@ -2231,9 +2268,19 @@ describe('ReactDOMServerPartialHydration', () => {
22312268
await promise;
22322269
});
22332270

2234-
expect(clicksOnChild).toBe(1);
2235-
// This will be zero due to the stopPropagation.
2236-
expect(clicksOnParent).toBe(0);
2271+
if (
2272+
gate(
2273+
flags =>
2274+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2275+
)
2276+
) {
2277+
expect(clicksOnChild).toBe(0);
2278+
expect(clicksOnParent).toBe(0);
2279+
} else {
2280+
expect(clicksOnChild).toBe(1);
2281+
// This will be zero due to the stopPropagation.
2282+
expect(clicksOnParent).toBe(0);
2283+
}
22372284

22382285
document.body.removeChild(container);
22392286
});
@@ -2310,8 +2357,16 @@ describe('ReactDOMServerPartialHydration', () => {
23102357
});
23112358

23122359
// We're now full hydrated.
2313-
2314-
expect(clicks).toBe(1);
2360+
if (
2361+
gate(
2362+
flags =>
2363+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2364+
)
2365+
) {
2366+
expect(clicks).toBe(0);
2367+
} else {
2368+
expect(clicks).toBe(1);
2369+
}
23152370

23162371
document.body.removeChild(parentContainer);
23172372
});
@@ -2580,8 +2635,20 @@ describe('ReactDOMServerPartialHydration', () => {
25802635
await promise;
25812636
});
25822637

2583-
expect(submits).toBe(1);
2584-
expect(container.textContent).toBe('Hello');
2638+
if (
2639+
gate(
2640+
flags =>
2641+
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
2642+
)
2643+
) {
2644+
// discrete event not replayed
2645+
expect(submits).toBe(0);
2646+
expect(container.textContent).toBe('Click meHello');
2647+
} else {
2648+
expect(submits).toBe(1);
2649+
expect(container.textContent).toBe('Hello');
2650+
}
2651+
25852652
document.body.removeChild(container);
25862653
});
25872654

0 commit comments

Comments
 (0)