Skip to content

Commit 8310854

Browse files
authored
Clean up enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay (#26521)
This flag is already enabled everywhere except for www, which is blocked by a few tests that assert on the old behavior. Once www is ready, I'll land this.
1 parent ca01f35 commit 8310854

14 files changed

+74
-546
lines changed

packages/react-dom-bindings/src/events/ReactDOMEventListener.js

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import type {AnyNativeEvent} from '../events/PluginModuleType';
1212
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1313
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1414
import type {DOMEventName} from '../events/DOMEventNames';
15-
import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags';
15+
1616
import {
1717
isDiscreteEventThatRequiresHydration,
18-
queueDiscreteEvent,
19-
hasQueuedDiscreteEvents,
2018
clearIfContinuousEvent,
2119
queueIfContinuousEvent,
2220
} from './ReactDOMEventReplaying';
@@ -156,119 +154,7 @@ export function dispatchEvent(
156154
if (!_enabled) {
157155
return;
158156
}
159-
if (enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay) {
160-
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(
161-
domEventName,
162-
eventSystemFlags,
163-
targetContainer,
164-
nativeEvent,
165-
);
166-
} else {
167-
dispatchEventOriginal(
168-
domEventName,
169-
eventSystemFlags,
170-
targetContainer,
171-
nativeEvent,
172-
);
173-
}
174-
}
175-
176-
function dispatchEventOriginal(
177-
domEventName: DOMEventName,
178-
eventSystemFlags: EventSystemFlags,
179-
targetContainer: EventTarget,
180-
nativeEvent: AnyNativeEvent,
181-
) {
182-
// TODO: replaying capture phase events is currently broken
183-
// because we used to do it during top-level native bubble handlers
184-
// but now we use different bubble and capture handlers.
185-
// In eager mode, we attach capture listeners early, so we need
186-
// to filter them out until we fix the logic to handle them correctly.
187-
const allowReplay = (eventSystemFlags & IS_CAPTURE_PHASE) === 0;
188157

189-
if (
190-
allowReplay &&
191-
hasQueuedDiscreteEvents() &&
192-
isDiscreteEventThatRequiresHydration(domEventName)
193-
) {
194-
// If we already have a queue of discrete events, and this is another discrete
195-
// event, then we can't dispatch it regardless of its target, since they
196-
// need to dispatch in order.
197-
queueDiscreteEvent(
198-
null, // Flags that we're not actually blocked on anything as far as we know.
199-
domEventName,
200-
eventSystemFlags,
201-
targetContainer,
202-
nativeEvent,
203-
);
204-
return;
205-
}
206-
207-
const blockedOn = findInstanceBlockingEvent(
208-
domEventName,
209-
eventSystemFlags,
210-
targetContainer,
211-
nativeEvent,
212-
);
213-
if (blockedOn === null) {
214-
dispatchEventForPluginEventSystem(
215-
domEventName,
216-
eventSystemFlags,
217-
nativeEvent,
218-
return_targetInst,
219-
targetContainer,
220-
);
221-
if (allowReplay) {
222-
clearIfContinuousEvent(domEventName, nativeEvent);
223-
}
224-
return;
225-
}
226-
227-
if (allowReplay) {
228-
if (isDiscreteEventThatRequiresHydration(domEventName)) {
229-
// This to be replayed later once the target is available.
230-
queueDiscreteEvent(
231-
blockedOn,
232-
domEventName,
233-
eventSystemFlags,
234-
targetContainer,
235-
nativeEvent,
236-
);
237-
return;
238-
}
239-
if (
240-
queueIfContinuousEvent(
241-
blockedOn,
242-
domEventName,
243-
eventSystemFlags,
244-
targetContainer,
245-
nativeEvent,
246-
)
247-
) {
248-
return;
249-
}
250-
// We need to clear only if we didn't queue because
251-
// queueing is accumulative.
252-
clearIfContinuousEvent(domEventName, nativeEvent);
253-
}
254-
255-
// This is not replayable so we'll invoke it but without a target,
256-
// in case the event system needs to trace it.
257-
dispatchEventForPluginEventSystem(
258-
domEventName,
259-
eventSystemFlags,
260-
nativeEvent,
261-
null,
262-
targetContainer,
263-
);
264-
}
265-
266-
function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(
267-
domEventName: DOMEventName,
268-
eventSystemFlags: EventSystemFlags,
269-
targetContainer: EventTarget,
270-
nativeEvent: AnyNativeEvent,
271-
) {
272158
let blockedOn = findInstanceBlockingEvent(
273159
domEventName,
274160
eventSystemFlags,

packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js

Lines changed: 10 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {EventSystemFlags} from './EventSystemFlags';
1414
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1515
import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
1616

17-
import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags';
1817
import {
1918
unstable_scheduleCallback as scheduleCallback,
2019
unstable_NormalPriority as NormalPriority,
@@ -24,12 +23,8 @@ import {
2423
getContainerFromFiber,
2524
getSuspenseInstanceFromFiber,
2625
} from 'react-reconciler/src/ReactFiberTreeReflection';
27-
import {
28-
findInstanceBlockingEvent,
29-
return_targetInst,
30-
} from './ReactDOMEventListener';
26+
import {findInstanceBlockingEvent} from './ReactDOMEventListener';
3127
import {setReplayingEvent, resetReplayingEvent} from './CurrentReplayingEvent';
32-
import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
3328
import {
3429
getInstanceFromNode,
3530
getClosestInstanceFromNode,
@@ -39,8 +34,6 @@ import {isHigherEventPriority} from 'react-reconciler/src/ReactEventPriorities';
3934
import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
4035

4136
import {
42-
attemptSynchronousHydration,
43-
attemptDiscreteHydration,
4437
attemptContinuousHydration,
4538
attemptHydrationAtCurrentPriority,
4639
} from 'react-reconciler/src/ReactFiberReconciler';
@@ -150,48 +143,6 @@ function createQueuedReplayableEvent(
150143
};
151144
}
152145

153-
export function queueDiscreteEvent(
154-
blockedOn: null | Container | SuspenseInstance,
155-
domEventName: DOMEventName,
156-
eventSystemFlags: EventSystemFlags,
157-
targetContainer: EventTarget,
158-
nativeEvent: AnyNativeEvent,
159-
): void {
160-
if (enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay) {
161-
return;
162-
}
163-
const queuedEvent = createQueuedReplayableEvent(
164-
blockedOn,
165-
domEventName,
166-
eventSystemFlags,
167-
targetContainer,
168-
nativeEvent,
169-
);
170-
queuedDiscreteEvents.push(queuedEvent);
171-
if (queuedDiscreteEvents.length === 1) {
172-
// If this was the first discrete event, we might be able to
173-
// synchronously unblock it so that preventDefault still works.
174-
while (queuedEvent.blockedOn !== null) {
175-
const fiber = getInstanceFromNode(queuedEvent.blockedOn);
176-
if (fiber === null) {
177-
break;
178-
}
179-
attemptSynchronousHydration(fiber);
180-
if (queuedEvent.blockedOn === null) {
181-
// We got unblocked by hydration. Let's try again.
182-
replayUnblockedEvents();
183-
// If we're reblocked, on an inner boundary, we might need
184-
// to attempt hydrating that one.
185-
continue;
186-
} else {
187-
// We're still blocked from hydration, we have to give up
188-
// and replay later.
189-
break;
190-
}
191-
}
192-
}
193-
}
194-
195146
// Resets the replaying for this type of continuous event to no event.
196147
export function clearIfContinuousEvent(
197148
domEventName: DOMEventName,
@@ -433,26 +384,14 @@ function attemptReplayContinuousQueuedEvent(
433384
queuedEvent.nativeEvent,
434385
);
435386
if (nextBlockedOn === null) {
436-
if (enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay) {
437-
const nativeEvent = queuedEvent.nativeEvent;
438-
const nativeEventClone = new nativeEvent.constructor(
439-
nativeEvent.type,
440-
(nativeEvent: any),
441-
);
442-
setReplayingEvent(nativeEventClone);
443-
nativeEvent.target.dispatchEvent(nativeEventClone);
444-
resetReplayingEvent();
445-
} else {
446-
setReplayingEvent(queuedEvent.nativeEvent);
447-
dispatchEventForPluginEventSystem(
448-
queuedEvent.domEventName,
449-
queuedEvent.eventSystemFlags,
450-
queuedEvent.nativeEvent,
451-
return_targetInst,
452-
targetContainer,
453-
);
454-
resetReplayingEvent();
455-
}
387+
const nativeEvent = queuedEvent.nativeEvent;
388+
const nativeEventClone = new nativeEvent.constructor(
389+
nativeEvent.type,
390+
(nativeEvent: any),
391+
);
392+
setReplayingEvent(nativeEventClone);
393+
nativeEvent.target.dispatchEvent(nativeEventClone);
394+
resetReplayingEvent();
456395
} else {
457396
// We're still blocked. Try again later.
458397
const fiber = getInstanceFromNode(nextBlockedOn);
@@ -480,56 +419,7 @@ function attemptReplayContinuousQueuedEventInMap(
480419

481420
function replayUnblockedEvents() {
482421
hasScheduledReplayAttempt = false;
483-
if (!enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay) {
484-
// First replay discrete events.
485-
while (queuedDiscreteEvents.length > 0) {
486-
const nextDiscreteEvent = queuedDiscreteEvents[0];
487-
if (nextDiscreteEvent.blockedOn !== null) {
488-
// We're still blocked.
489-
// Increase the priority of this boundary to unblock
490-
// the next discrete event.
491-
const fiber = getInstanceFromNode(nextDiscreteEvent.blockedOn);
492-
if (fiber !== null) {
493-
attemptDiscreteHydration(fiber);
494-
}
495-
break;
496-
}
497-
const targetContainers = nextDiscreteEvent.targetContainers;
498-
while (targetContainers.length > 0) {
499-
const targetContainer = targetContainers[0];
500-
const nextBlockedOn = findInstanceBlockingEvent(
501-
nextDiscreteEvent.domEventName,
502-
nextDiscreteEvent.eventSystemFlags,
503-
targetContainer,
504-
nextDiscreteEvent.nativeEvent,
505-
);
506-
if (nextBlockedOn === null) {
507-
// This whole function is in !enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
508-
// so we don't need the new replay behavior code branch.
509-
setReplayingEvent(nextDiscreteEvent.nativeEvent);
510-
dispatchEventForPluginEventSystem(
511-
nextDiscreteEvent.domEventName,
512-
nextDiscreteEvent.eventSystemFlags,
513-
nextDiscreteEvent.nativeEvent,
514-
return_targetInst,
515-
targetContainer,
516-
);
517-
resetReplayingEvent();
518-
} else {
519-
// We're still blocked. Try again later.
520-
nextDiscreteEvent.blockedOn = nextBlockedOn;
521-
break;
522-
}
523-
// This target container was successfully dispatched. Try the next.
524-
targetContainers.shift();
525-
}
526-
if (nextDiscreteEvent.blockedOn === null) {
527-
// We've successfully replayed the first event. Let's try the next one.
528-
queuedDiscreteEvents.shift();
529-
}
530-
}
531-
}
532-
// Next replay any continuous events.
422+
// Replay any continuous events.
533423
if (queuedFocus !== null && attemptReplayContinuousQueuedEvent(queuedFocus)) {
534424
queuedFocus = null;
535425
}

0 commit comments

Comments
 (0)