Skip to content

Commit 0c83ba8

Browse files
committed
Add behind feature flag
1 parent 7ba61c6 commit 0c83ba8

10 files changed

+37
-18
lines changed

packages/react-dom/src/events/ReactDOMUpdateBatching.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
needsStateRestore,
1010
restoreStateIfNeeded,
1111
} from './ReactDOMControlledComponent';
12+
import {enableDiscreteEventFlushingChange} from 'shared/ReactFeatureFlags';
1213

1314
// Used as a way to call batchedUpdates when we don't have a reference to
1415
// the renderer. Such as when we're dispatching events or if third party
@@ -89,24 +90,31 @@ export function discreteUpdates(fn, a, b, c, d) {
8990

9091
let lastFlushedEventTimeStamp = 0;
9192
export function flushDiscreteUpdatesIfNeeded(timeStamp: number) {
92-
// event.timeStamp isn't overly reliable due to inconsistencies in
93-
// how different browsers have historically provided the time stamp.
94-
// Some browsers provide high-resolution time stamps for all events,
95-
// some provide low-resolution time stamps for all events. FF < 52
96-
// even mixes both time stamps together. Some browsers even report
97-
// negative time stamps or time stamps that are 0 (iOS9) in some cases.
98-
// Given we are only comparing two time stamps with equality (!==),
99-
// we are safe from the resolution differences. If the time stamp is 0
100-
// we bail-out of preventing the flush, which can affect semantics,
101-
// such as if an earlier flush removes or adds event listeners that
102-
// are fired in the subsequent flush. However, this is the same
103-
// behaviour as we had before this change, so the risks are low.
104-
if (
105-
!isInsideEventHandler &&
106-
(timeStamp === 0 || lastFlushedEventTimeStamp !== timeStamp)
107-
) {
108-
lastFlushedEventTimeStamp = timeStamp;
109-
flushDiscreteUpdatesImpl();
93+
if (enableDiscreteEventFlushingChange) {
94+
// event.timeStamp isn't overly reliable due to inconsistencies in
95+
// how different browsers have historically provided the time stamp.
96+
// Some browsers provide high-resolution time stamps for all events,
97+
// some provide low-resolution time stamps for all events. FF < 52
98+
// even mixes both time stamps together. Some browsers even report
99+
// negative time stamps or time stamps that are 0 (iOS9) in some cases.
100+
// Given we are only comparing two time stamps with equality (!==),
101+
// we are safe from the resolution differences. If the time stamp is 0
102+
// we bail-out of preventing the flush, which can affect semantics,
103+
// such as if an earlier flush removes or adds event listeners that
104+
// are fired in the subsequent flush. However, this is the same
105+
// behaviour as we had before this change, so the risks are low.
106+
if (
107+
!isInsideEventHandler &&
108+
(timeStamp === 0 || lastFlushedEventTimeStamp !== timeStamp)
109+
) {
110+
lastFlushedEventTimeStamp = timeStamp;
111+
flushDiscreteUpdatesImpl();
112+
}
113+
} else {
114+
if (!isInsideEventHandler) {
115+
lastFlushedEventTimeStamp = timeStamp;
116+
flushDiscreteUpdatesImpl();
117+
}
110118
}
111119
}
112120

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,5 @@ export const deferRenderPhaseUpdateToNextBatch = true;
125125

126126
// Replacement for runWithPriority in React internals.
127127
export const decoupleUpdatePriorityFromScheduler = false;
128+
129+
export const enableDiscreteEventFlushingChange = false;

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4848
export const enableNewReconciler = false;
4949
export const deferRenderPhaseUpdateToNextBatch = true;
5050
export const decoupleUpdatePriorityFromScheduler = false;
51+
export const enableDiscreteEventFlushingChange = false;
5152

5253
// Flow magic to verify the exports of this file match the original version.
5354
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = false;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = false;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = false;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = false;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = false;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.testing.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const enableFilterEmptyStringAttributesDOM = false;
4747
export const enableNewReconciler = false;
4848
export const deferRenderPhaseUpdateToNextBatch = true;
4949
export const decoupleUpdatePriorityFromScheduler = false;
50+
export const enableDiscreteEventFlushingChange = true;
5051

5152
// Flow magic to verify the exports of this file match the original version.
5253
// eslint-disable-next-line no-unused-vars

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export const disableTextareaChildren = __EXPERIMENTAL__;
7575

7676
export const warnUnstableRenderSubtreeIntoContainer = false;
7777

78+
export const enableDiscreteEventFlushingChange = true;
79+
7880
// Enable forked reconciler. Piggy-backing on the "variant" global so that we
7981
// don't have to add another test dimension. The build system will compile this
8082
// to the correct value.

0 commit comments

Comments
 (0)