From a77dd13ede337175e94a7a1d4198ff440a5cd87b Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Fri, 26 Mar 2021 00:05:59 -0500 Subject: [PATCH] Delete enableDiscreteEventFlushingChange (#21110) This flag was meant to avoid flushing discrete updates unnecessarily, if multiple discrete events were dispatched in response to the same platform event. But since we now flush all discrete events at the end of the task, in a microtask, it no longer has any effect. --- .../src/events/ReactDOMUpdateBatching.js | 30 +++---------------- packages/shared/ReactFeatureFlags.js | 2 -- .../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 | 2 -- 10 files changed, 4 insertions(+), 37 deletions(-) diff --git a/packages/react-dom/src/events/ReactDOMUpdateBatching.js b/packages/react-dom/src/events/ReactDOMUpdateBatching.js index 01625f45d2653..283afb5b84d63 100644 --- a/packages/react-dom/src/events/ReactDOMUpdateBatching.js +++ b/packages/react-dom/src/events/ReactDOMUpdateBatching.js @@ -9,7 +9,6 @@ import { needsStateRestore, restoreStateIfNeeded, } from './ReactDOMControlledComponent'; -import {enableDiscreteEventFlushingChange} from 'shared/ReactFeatureFlags'; // Used as a way to call batchedUpdates when we don't have a reference to // the renderer. Such as when we're dispatching events or if third party @@ -75,6 +74,7 @@ export function batchedEventUpdates(fn, a, b) { } } +// TODO: Replace with flushSync export function discreteUpdates(fn, a, b, c, d) { const prevIsInsideEventHandler = isInsideEventHandler; isInsideEventHandler = true; @@ -88,32 +88,10 @@ export function discreteUpdates(fn, a, b, c, d) { } } -let lastFlushedEventTimeStamp = 0; +// TODO: Replace with flushSync export function flushDiscreteUpdatesIfNeeded(timeStamp: number) { - if (enableDiscreteEventFlushingChange) { - // event.timeStamp isn't overly reliable due to inconsistencies in - // how different browsers have historically provided the time stamp. - // Some browsers provide high-resolution time stamps for all events, - // some provide low-resolution time stamps for all events. FF < 52 - // even mixes both time stamps together. Some browsers even report - // negative time stamps or time stamps that are 0 (iOS9) in some cases. - // Given we are only comparing two time stamps with equality (!==), - // we are safe from the resolution differences. If the time stamp is 0 - // we bail-out of preventing the flush, which can affect semantics, - // such as if an earlier flush removes or adds event listeners that - // are fired in the subsequent flush. However, this is the same - // behaviour as we had before this change, so the risks are low. - if ( - !isInsideEventHandler && - (timeStamp === 0 || lastFlushedEventTimeStamp !== timeStamp) - ) { - lastFlushedEventTimeStamp = timeStamp; - flushDiscreteUpdatesImpl(); - } - } else { - if (!isInsideEventHandler) { - flushDiscreteUpdatesImpl(); - } + if (!isInsideEventHandler) { + flushDiscreteUpdatesImpl(); } } diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index a1e9c42d3d1c8..dc77e5482abbc 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -155,8 +155,6 @@ export const enableLegacyFBSupport = false; // new behavior. export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; - export const enableUseRefAccessWarning = false; export const enableRecursiveCommitTraversal = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 7d5c5a6c40cc4..34d521a50834c 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -50,7 +50,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index cd2979fc400f9..c7d5331108375 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index c7f1f1a4739d4..100ddb697dbb4 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index 895ebad1d809e..ceea27b19c59c 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 832f56e6fa093..61ec5b6564dcf 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = true; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 351b0934c7924..26b2b9a279219 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index b25ac0073e944..12da19a71c6bc 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -49,7 +49,6 @@ export const deletedTreeCleanUpLevel = 1; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const enableDiscreteEventFlushingChange = true; export const enableStrictEffects = false; export const createRootStrictEffectsByDefault = false; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index dab1a37bc5c69..f145335353940 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -83,8 +83,6 @@ export const disableTextareaChildren = __EXPERIMENTAL__; export const warnUnstableRenderSubtreeIntoContainer = false; -export const enableDiscreteEventFlushingChange = true; - // Enable forked reconciler. Piggy-backing on the "variant" global so that we // don't have to add another test dimension. The build system will compile this // to the correct value.