Skip to content

Commit

Permalink
Delete enableDiscreteEventFlushingChange (facebook#21110)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Apr 11, 2021
1 parent b8cfa81 commit 837510d
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 37 deletions.
30 changes: 4 additions & 26 deletions packages/react-dom/src/events/ReactDOMUpdateBatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 837510d

Please sign in to comment.