From c2b19c3efadd0615a3db17d65cc8c0eb7685d8ed Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 8 Feb 2021 17:48:31 +0000 Subject: [PATCH] Align event group constant naming with lane naming (#20744) * Rename ContinuousEvent to DefaultEvent * Rename UserBlockingEvent to ContinuousEvent --- packages/react-dom/src/client/ReactDOM.js | 6 ++--- .../src/events/DOMEventProperties.js | 24 ++++++++----------- .../src/events/ReactDOMEventListener.js | 14 ++++------- .../src/events/ReactDOMEventReplaying.js | 8 +++---- .../src/ReactFiberReconciler.js | 10 ++++---- .../src/ReactFiberReconciler.new.js | 2 +- .../src/ReactFiberReconciler.old.js | 2 +- packages/shared/ReactTypes.js | 4 ++-- 8 files changed, 31 insertions(+), 39 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index fcd54a58ede5d..66ae001c3b27d 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -32,7 +32,7 @@ import { flushPassiveEffects, IsThisRendererActing, attemptSynchronousHydration, - attemptUserBlockingHydration, + attemptDiscreteHydration, attemptContinuousHydration, attemptHydrationAtCurrentPriority, runWithPriority, @@ -56,7 +56,7 @@ import { import {restoreControlledState} from './ReactDOMComponent'; import { setAttemptSynchronousHydration, - setAttemptUserBlockingHydration, + setAttemptDiscreteHydration, setAttemptContinuousHydration, setAttemptHydrationAtCurrentPriority, queueExplicitHydrationTarget, @@ -71,7 +71,7 @@ import { } from '../events/ReactDOMControlledComponent'; setAttemptSynchronousHydration(attemptSynchronousHydration); -setAttemptUserBlockingHydration(attemptUserBlockingHydration); +setAttemptDiscreteHydration(attemptDiscreteHydration); setAttemptContinuousHydration(attemptContinuousHydration); setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority); setGetCurrentUpdatePriority(getCurrentUpdateLanePriority); diff --git a/packages/react-dom/src/events/DOMEventProperties.js b/packages/react-dom/src/events/DOMEventProperties.js index abdd3a256e34d..9fe967737e935 100644 --- a/packages/react-dom/src/events/DOMEventProperties.js +++ b/packages/react-dom/src/events/DOMEventProperties.js @@ -17,11 +17,7 @@ import { ANIMATION_START, TRANSITION_END, } from './DOMEventNames'; -import { - DiscreteEvent, - UserBlockingEvent, - ContinuousEvent, -} from 'shared/ReactTypes'; +import {DiscreteEvent, ContinuousEvent, DefaultEvent} from 'shared/ReactTypes'; import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags'; @@ -97,7 +93,7 @@ if (enableCreateEventHandleAPI) { } // prettier-ignore -const userBlockingPairsForSimpleEventPlugin: Array = [ +const continuousPairsForSimpleEventPlugin: Array = [ ('drag': DOMEventName), 'drag', ('dragenter': DOMEventName), 'dragEnter', ('dragexit': DOMEventName), 'dragExit', @@ -116,7 +112,7 @@ const userBlockingPairsForSimpleEventPlugin: Array = [ ]; // prettier-ignore -const continuousPairsForSimpleEventPlugin: Array = [ +const defaultPairsForSimpleEventPlugin: Array = [ ('abort': DOMEventName), 'abort', (ANIMATION_END: DOMEventName), 'animationEnd', (ANIMATION_ITERATION: DOMEventName), 'animationIteration', @@ -190,10 +186,10 @@ export function getEventPriorityForPluginSystem( domEventName: DOMEventName, ): EventPriority { const priority = eventPriorities.get(domEventName); - // Default to a ContinuousEvent. Note: we might + // Default to a DefaultEvent. Note: we might // want to warn if we can't detect the priority // for the event. - return priority === undefined ? ContinuousEvent : priority; + return priority === undefined ? DefaultEvent : priority; } export function getEventPriorityForListenerSystem( @@ -210,7 +206,7 @@ export function getEventPriorityForListenerSystem( type, ); } - return ContinuousEvent; + return DefaultEvent; } export function registerSimpleEvents() { @@ -218,13 +214,13 @@ export function registerSimpleEvents() { discreteEventPairsForSimpleEventPlugin, DiscreteEvent, ); - registerSimplePluginEventsAndSetTheirPriorities( - userBlockingPairsForSimpleEventPlugin, - UserBlockingEvent, - ); registerSimplePluginEventsAndSetTheirPriorities( continuousPairsForSimpleEventPlugin, ContinuousEvent, ); + registerSimplePluginEventsAndSetTheirPriorities( + defaultPairsForSimpleEventPlugin, + DefaultEvent, + ); setEventPriorities(otherDiscreteEvents, DiscreteEvent); } diff --git a/packages/react-dom/src/events/ReactDOMEventListener.js b/packages/react-dom/src/events/ReactDOMEventListener.js index dcb2cfb9fd70d..4b87da2c320d7 100644 --- a/packages/react-dom/src/events/ReactDOMEventListener.js +++ b/packages/react-dom/src/events/ReactDOMEventListener.js @@ -43,11 +43,7 @@ import { decoupleUpdatePriorityFromScheduler, enableNewReconciler, } from 'shared/ReactFeatureFlags'; -import { - UserBlockingEvent, - ContinuousEvent, - DiscreteEvent, -} from 'shared/ReactTypes'; +import {ContinuousEvent, DefaultEvent, DiscreteEvent} from 'shared/ReactTypes'; import {getEventPriorityForPluginSystem} from './DOMEventProperties'; import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem'; import { @@ -118,10 +114,10 @@ export function createEventListenerWrapperWithPriority( case DiscreteEvent: listenerWrapper = dispatchDiscreteEvent; break; - case UserBlockingEvent: - listenerWrapper = dispatchUserBlockingUpdate; - break; case ContinuousEvent: + listenerWrapper = dispatchContinuousEvent; + break; + case DefaultEvent: default: listenerWrapper = dispatchEvent; break; @@ -157,7 +153,7 @@ function dispatchDiscreteEvent( ); } -function dispatchUserBlockingUpdate( +function dispatchContinuousEvent( domEventName, eventSystemFlags, container, diff --git a/packages/react-dom/src/events/ReactDOMEventReplaying.js b/packages/react-dom/src/events/ReactDOMEventReplaying.js index a56487c0928dd..8cfacce3e0e95 100644 --- a/packages/react-dom/src/events/ReactDOMEventReplaying.js +++ b/packages/react-dom/src/events/ReactDOMEventReplaying.js @@ -39,10 +39,10 @@ export function setAttemptSynchronousHydration(fn: (fiber: Object) => void) { attemptSynchronousHydration = fn; } -let attemptUserBlockingHydration: (fiber: Object) => void; +let attemptDiscreteHydration: (fiber: Object) => void; -export function setAttemptUserBlockingHydration(fn: (fiber: Object) => void) { - attemptUserBlockingHydration = fn; +export function setAttemptDiscreteHydration(fn: (fiber: Object) => void) { + attemptDiscreteHydration = fn; } let attemptContinuousHydration: (fiber: Object) => void; @@ -489,7 +489,7 @@ function replayUnblockedEvents() { // the next discrete event. const fiber = getInstanceFromNode(nextDiscreteEvent.blockedOn); if (fiber !== null) { - attemptUserBlockingHydration(fiber); + attemptDiscreteHydration(fiber); } break; } diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index a0b7661d4c986..292d3aaf2a323 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -29,7 +29,7 @@ import { IsThisRendererActing as IsThisRendererActing_old, getPublicRootInstance as getPublicRootInstance_old, attemptSynchronousHydration as attemptSynchronousHydration_old, - attemptUserBlockingHydration as attemptUserBlockingHydration_old, + attemptDiscreteHydration as attemptDiscreteHydration_old, attemptContinuousHydration as attemptContinuousHydration_old, attemptHydrationAtCurrentPriority as attemptHydrationAtCurrentPriority_old, findHostInstance as findHostInstance_old, @@ -69,7 +69,7 @@ import { IsThisRendererActing as IsThisRendererActing_new, getPublicRootInstance as getPublicRootInstance_new, attemptSynchronousHydration as attemptSynchronousHydration_new, - attemptUserBlockingHydration as attemptUserBlockingHydration_new, + attemptDiscreteHydration as attemptDiscreteHydration_new, attemptContinuousHydration as attemptContinuousHydration_new, attemptHydrationAtCurrentPriority as attemptHydrationAtCurrentPriority_new, findHostInstance as findHostInstance_new, @@ -134,9 +134,9 @@ export const getPublicRootInstance = enableNewReconciler export const attemptSynchronousHydration = enableNewReconciler ? attemptSynchronousHydration_new : attemptSynchronousHydration_old; -export const attemptUserBlockingHydration = enableNewReconciler - ? attemptUserBlockingHydration_new - : attemptUserBlockingHydration_old; +export const attemptDiscreteHydration = enableNewReconciler + ? attemptDiscreteHydration_new + : attemptDiscreteHydration_old; export const attemptContinuousHydration = enableNewReconciler ? attemptContinuousHydration_new : attemptContinuousHydration_old; diff --git a/packages/react-reconciler/src/ReactFiberReconciler.new.js b/packages/react-reconciler/src/ReactFiberReconciler.new.js index 57107e964245d..439f69634e9bb 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.new.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.new.js @@ -396,7 +396,7 @@ function markRetryLaneIfNotHydrated(fiber: Fiber, retryLane: Lane) { } } -export function attemptUserBlockingHydration(fiber: Fiber): void { +export function attemptDiscreteHydration(fiber: Fiber): void { if (fiber.tag !== SuspenseComponent) { // We ignore HostRoots here because we can't increase // their priority and they should not suspend on I/O, diff --git a/packages/react-reconciler/src/ReactFiberReconciler.old.js b/packages/react-reconciler/src/ReactFiberReconciler.old.js index ba9a796f63002..f9e4a7cdf0d7c 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.old.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.old.js @@ -396,7 +396,7 @@ function markRetryLaneIfNotHydrated(fiber: Fiber, retryLane: Lane) { } } -export function attemptUserBlockingHydration(fiber: Fiber): void { +export function attemptDiscreteHydration(fiber: Fiber): void { if (fiber.tag !== SuspenseComponent) { // We ignore HostRoots here because we can't increase // their priority and they should not suspend on I/O, diff --git a/packages/shared/ReactTypes.js b/packages/shared/ReactTypes.js index 01708f731e9a9..ae428508d1b2c 100644 --- a/packages/shared/ReactTypes.js +++ b/packages/shared/ReactTypes.js @@ -89,8 +89,8 @@ export type RefObject = {| export type EventPriority = 0 | 1 | 2; export const DiscreteEvent: EventPriority = 0; -export const UserBlockingEvent: EventPriority = 1; -export const ContinuousEvent: EventPriority = 2; +export const ContinuousEvent: EventPriority = 1; +export const DefaultEvent: EventPriority = 2; export type ReactScope = {| $$typeof: Symbol | number,