Skip to content

Commit

Permalink
Sync hydrate discrete events in capture phase and dont replay discret…
Browse files Browse the repository at this point in the history
…e events (#22448)
  • Loading branch information
salazarm committed Oct 4, 2021
1 parent a4bc8ae commit 0ecbbe1
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 102 deletions.
Expand Up @@ -1905,10 +1905,19 @@ describe('ReactDOMServerPartialHydration', () => {
resolve();
await promise;
});
expect(clicks).toBe(1);

expect(container.textContent).toBe('Hello');

if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(clicks).toBe(0);
expect(container.textContent).toBe('Click meHello');
} else {
expect(clicks).toBe(1);
expect(container.textContent).toBe('Hello');
}
document.body.removeChild(container);
});

Expand Down Expand Up @@ -1991,7 +2000,16 @@ describe('ReactDOMServerPartialHydration', () => {
await promise;
});

expect(onEvent).toHaveBeenCalledTimes(2);
if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(onEvent).toHaveBeenCalledTimes(0);
} else {
expect(onEvent).toHaveBeenCalledTimes(2);
}

document.body.removeChild(container);
});
Expand Down Expand Up @@ -2072,7 +2090,17 @@ describe('ReactDOMServerPartialHydration', () => {
resolve();
await promise;
});
expect(clicks).toBe(2);

if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(clicks).toBe(0);
} else {
expect(clicks).toBe(2);
}

document.body.removeChild(container);
});
Expand Down Expand Up @@ -2158,7 +2186,16 @@ describe('ReactDOMServerPartialHydration', () => {
resolve();
await promise;
});
expect(onEvent).toHaveBeenCalledTimes(2);
if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(onEvent).toHaveBeenCalledTimes(0);
} else {
expect(onEvent).toHaveBeenCalledTimes(2);
}

document.body.removeChild(container);
});
Expand Down Expand Up @@ -2231,9 +2268,19 @@ describe('ReactDOMServerPartialHydration', () => {
await promise;
});

expect(clicksOnChild).toBe(1);
// This will be zero due to the stopPropagation.
expect(clicksOnParent).toBe(0);
if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(clicksOnChild).toBe(0);
expect(clicksOnParent).toBe(0);
} else {
expect(clicksOnChild).toBe(1);
// This will be zero due to the stopPropagation.
expect(clicksOnParent).toBe(0);
}

document.body.removeChild(container);
});
Expand Down Expand Up @@ -2310,8 +2357,16 @@ describe('ReactDOMServerPartialHydration', () => {
});

// We're now full hydrated.

expect(clicks).toBe(1);
if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
expect(clicks).toBe(0);
} else {
expect(clicks).toBe(1);
}

document.body.removeChild(parentContainer);
});
Expand Down Expand Up @@ -2580,8 +2635,20 @@ describe('ReactDOMServerPartialHydration', () => {
await promise;
});

expect(submits).toBe(1);
expect(container.textContent).toBe('Hello');
if (
gate(
flags =>
flags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
)
) {
// discrete event not replayed
expect(submits).toBe(0);
expect(container.textContent).toBe('Click meHello');
} else {
expect(submits).toBe(1);
expect(container.textContent).toBe('Hello');
}

document.body.removeChild(container);
});

Expand Down

0 comments on commit 0ecbbe1

Please sign in to comment.