From cfd6b07e5891e4a75ebcffc2232700e16828eaff Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 19 Apr 2022 23:26:26 -0400 Subject: [PATCH] Land enableSelectiveHydration flag This flag is already enabled on all relevant surfaces. We can remove it. --- .../src/events/ReactDOMEventReplaying.js | 93 +++++++++---------- packages/shared/ReactFeatureFlags.js | 1 - .../forks/ReactFeatureFlags.native-fb.js | 1 - .../forks/ReactFeatureFlags.native-oss.js | 1 - .../forks/ReactFeatureFlags.test-renderer.js | 1 - .../ReactFeatureFlags.test-renderer.native.js | 1 - .../ReactFeatureFlags.test-renderer.www.js | 1 - .../shared/forks/ReactFeatureFlags.testing.js | 1 - .../forks/ReactFeatureFlags.testing.www.js | 1 - .../shared/forks/ReactFeatureFlags.www.js | 1 - 10 files changed, 43 insertions(+), 59 deletions(-) diff --git a/packages/react-dom/src/events/ReactDOMEventReplaying.js b/packages/react-dom/src/events/ReactDOMEventReplaying.js index 9de82a99a7be3..a5d669732b4ab 100644 --- a/packages/react-dom/src/events/ReactDOMEventReplaying.js +++ b/packages/react-dom/src/events/ReactDOMEventReplaying.js @@ -14,10 +14,7 @@ import type {EventSystemFlags} from './EventSystemFlags'; import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; -import { - enableSelectiveHydration, - enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay, -} from 'shared/ReactFeatureFlags'; +import {enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay} from 'shared/ReactFeatureFlags'; import { unstable_scheduleCallback as scheduleCallback, unstable_NormalPriority as NormalPriority, @@ -204,27 +201,25 @@ export function queueDiscreteEvent( nativeEvent, ); queuedDiscreteEvents.push(queuedEvent); - if (enableSelectiveHydration) { - if (queuedDiscreteEvents.length === 1) { - // If this was the first discrete event, we might be able to - // synchronously unblock it so that preventDefault still works. - while (queuedEvent.blockedOn !== null) { - const fiber = getInstanceFromNode(queuedEvent.blockedOn); - if (fiber === null) { - break; - } - attemptSynchronousHydration(fiber); - if (queuedEvent.blockedOn === null) { - // We got unblocked by hydration. Let's try again. - replayUnblockedEvents(); - // If we're reblocked, on an inner boundary, we might need - // to attempt hydrating that one. - continue; - } else { - // We're still blocked from hydration, we have to give up - // and replay later. - break; - } + if (queuedDiscreteEvents.length === 1) { + // If this was the first discrete event, we might be able to + // synchronously unblock it so that preventDefault still works. + while (queuedEvent.blockedOn !== null) { + const fiber = getInstanceFromNode(queuedEvent.blockedOn); + if (fiber === null) { + break; + } + attemptSynchronousHydration(fiber); + if (queuedEvent.blockedOn === null) { + // We got unblocked by hydration. Let's try again. + replayUnblockedEvents(); + // If we're reblocked, on an inner boundary, we might need + // to attempt hydrating that one. + continue; + } else { + // We're still blocked from hydration, we have to give up + // and replay later. + break; } } } @@ -428,33 +423,31 @@ function attemptExplicitHydrationTarget( } export function queueExplicitHydrationTarget(target: Node): void { - if (enableSelectiveHydration) { - // TODO: This will read the priority if it's dispatched by the React - // event system but not native events. Should read window.event.type, like - // we do for updates (getCurrentEventPriority). - const updatePriority = getCurrentUpdatePriority(); - const queuedTarget: QueuedHydrationTarget = { - blockedOn: null, - target: target, - priority: updatePriority, - }; - let i = 0; - for (; i < queuedExplicitHydrationTargets.length; i++) { - // Stop once we hit the first target with lower priority than - if ( - !isHigherEventPriority( - updatePriority, - queuedExplicitHydrationTargets[i].priority, - ) - ) { - break; - } - } - queuedExplicitHydrationTargets.splice(i, 0, queuedTarget); - if (i === 0) { - attemptExplicitHydrationTarget(queuedTarget); + // TODO: This will read the priority if it's dispatched by the React + // event system but not native events. Should read window.event.type, like + // we do for updates (getCurrentEventPriority). + const updatePriority = getCurrentUpdatePriority(); + const queuedTarget: QueuedHydrationTarget = { + blockedOn: null, + target: target, + priority: updatePriority, + }; + let i = 0; + for (; i < queuedExplicitHydrationTargets.length; i++) { + // Stop once we hit the first target with lower priority than + if ( + !isHigherEventPriority( + updatePriority, + queuedExplicitHydrationTargets[i].priority, + ) + ) { + break; } } + queuedExplicitHydrationTargets.splice(i, 0, queuedTarget); + if (i === 0) { + attemptExplicitHydrationTarget(queuedTarget); + } } function attemptReplayContinuousQueuedEvent( diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index aafe4c74d0440..e7709026c06ba 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -14,7 +14,6 @@ // ----------------------------------------------------------------------------- export const enableSuspenseServerRenderer = true; -export const enableSelectiveHydration = true; export const warnAboutDeprecatedLifecycles = true; export const enableLazyElements = true; export const enableComponentStackLocations = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index f2ce77374235e..91276255c938c 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -27,7 +27,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = __PROFILE__; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = false; export const enableCacheElement = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 43855df94f90d..cde2253facd7e 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = __PROFILE__; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = false; export const enableCacheElement = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 4283aa16e1201..b57c201b827fe 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = false; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = __EXPERIMENTAL__; export const enableCacheElement = __EXPERIMENTAL__; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index 938b4d136d73d..3e5b3cb9ce9a1 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = false; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = true; export const enableCacheElement = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 7ad5cc56d9d92..2da7337f3dc4b 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = false; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = true; export const enableCacheElement = true; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 0f65c001e5402..d9565b2fe0fc2 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = __PROFILE__; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = false; export const enableSuspenseServerRenderer = false; -export const enableSelectiveHydration = false; export const enableLazyElements = false; export const enableCache = __EXPERIMENTAL__; export const enableCacheElement = __EXPERIMENTAL__; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index 93d9860413db8..992a9b7ea9840 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -21,7 +21,6 @@ export const enableProfilerNestedUpdatePhase = false; export const enableProfilerNestedUpdateScheduledHook = false; export const enableUpdaterTracking = false; export const enableSuspenseServerRenderer = true; -export const enableSelectiveHydration = true; export const enableLazyElements = false; export const enableCache = true; export const enableCacheElement = true; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index a108f7a144b9e..12461e1455ea1 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -68,7 +68,6 @@ export const warnAboutStringRefs = false; export const warnAboutDefaultPropsOnFunctionComponents = false; export const enableGetInspectorDataForInstanceInProduction = false; export const enableSuspenseServerRenderer = true; -export const enableSelectiveHydration = true; export const enableLazyElements = true; export const enableCache = true;