From bfe806256917218b4e7b6cd2e8c467d03a8d2976 Mon Sep 17 00:00:00 2001 From: Marco Salazar Date: Wed, 1 Dec 2021 09:21:00 -0500 Subject: [PATCH] move invariant --- .../react-dom/src/events/ReactDOMEventReplaying.js | 12 +++++++++++- packages/react-dom/src/events/replayedEvent.js | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/react-dom/src/events/ReactDOMEventReplaying.js b/packages/react-dom/src/events/ReactDOMEventReplaying.js index 2275cfbcfb3a1..834862643fc13 100644 --- a/packages/react-dom/src/events/ReactDOMEventReplaying.js +++ b/packages/react-dom/src/events/ReactDOMEventReplaying.js @@ -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, @@ -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, () => { diff --git a/packages/react-dom/src/events/replayedEvent.js b/packages/react-dom/src/events/replayedEvent.js index 4b961985889ac..c7ab51ca4415f 100644 --- a/packages/react-dom/src/events/replayedEvent.js +++ b/packages/react-dom/src/events/replayedEvent.js @@ -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);