Skip to content

Commit

Permalink
move invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
salazarm committed Dec 1, 2021
1 parent f866d88 commit bfe8062
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 11 additions & 1 deletion packages/react-dom/src/events/ReactDOMEventReplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
import getEventTarget from './getEventTarget';
import {replayEventWrapper} from './replayedEvent';
import {isReplayingEvent, replayEventWrapper} from './replayedEvent';

import {
enableSelectiveHydration,
Expand Down Expand Up @@ -643,6 +643,16 @@ function replayEvent(
targetInst: null | NullTarget | Container | SuspenseInstance,
) {
const event = queuedEvent.nativeEvent;
if (isReplayingEvent(event)) {
// If an event reaches this codepath then it was recently unblocked.
// If the event is unblocked then it should never hit this codepath again after
// the initial unblocking since we'll just dispatch it directly without queueing it
// for replay.
throw new Error(
'Attempting to replay event that is already replaying. ' +
'This should never happen. This is a bug in React.',
);
}
if (enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay) {
const eventClone = new event.constructor(event.type, (event: any));
replayEventWrapper(eventClone, () => {
Expand Down
10 changes: 0 additions & 10 deletions packages/react-dom/src/events/replayedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ const eventsReplaying = new Set();
// This exists to avoid circular dependency between ReactDOMEventReplaying
// and DOMPluginEventSystem
export function replayEventWrapper(event: AnyNativeEvent, replay: () => void) {
if (isReplayingEvent(event)) {
// If an event reaches this codepath then it was recently unblocked.
// If the event is unblocked then it should never hit this codepath again after
// the initial unblocking since we'll just dispatch it directly without queueing it
// for replay.
throw new Error(
'Attempting to replay event that is already replaying. ' +
'This should never happen. This is a bug in React.',
);
}
eventsReplaying.add(event);
replay();
eventsReplaying.delete(event);
Expand Down

0 comments on commit bfe8062

Please sign in to comment.