Skip to content

Commit 207d4c3

Browse files
committed
Revert "Support nesting of startTransition and flushSync (alt) (#21149)"
This reverts commit faa1e12. * Support nesting of startTransition and flushSync * Unset transition before entering any special execution contexts Co-authored-by: Andrew Clark <[email protected]>
1 parent 2a7bb41 commit 207d4c3

File tree

4 files changed

+0
-93
lines changed

4 files changed

+0
-93
lines changed

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

-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ import {
4949
getCurrentUpdatePriority,
5050
setCurrentUpdatePriority,
5151
} from 'react-reconciler/src/ReactEventPriorities';
52-
import ReactSharedInternals from 'shared/ReactSharedInternals';
53-
54-
const {ReactCurrentBatchConfig} = ReactSharedInternals;
5552

5653
// TODO: can we stop exporting these?
5754
export let _enabled = true;
@@ -128,14 +125,11 @@ function dispatchContinuousEvent(
128125
nativeEvent,
129126
) {
130127
const previousPriority = getCurrentUpdatePriority();
131-
const prevTransition = ReactCurrentBatchConfig.transition;
132-
ReactCurrentBatchConfig.transition = 0;
133128
try {
134129
setCurrentUpdatePriority(ContinuousEventPriority);
135130
dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
136131
} finally {
137132
setCurrentUpdatePriority(previousPriority);
138-
ReactCurrentBatchConfig.transition = prevTransition;
139133
}
140134
}
141135

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

-22
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ const ceil = Math.ceil;
245245
const {
246246
ReactCurrentDispatcher,
247247
ReactCurrentOwner,
248-
ReactCurrentBatchConfig,
249248
IsSomeRendererActing,
250249
} = ReactSharedInternals;
251250

@@ -1063,14 +1062,11 @@ export function flushDiscreteUpdates() {
10631062

10641063
export function deferredUpdates<A>(fn: () => A): A {
10651064
const previousPriority = getCurrentUpdatePriority();
1066-
const prevTransition = ReactCurrentBatchConfig.transition;
10671065
try {
1068-
ReactCurrentBatchConfig.transition = 0;
10691066
setCurrentUpdatePriority(DefaultEventPriority);
10701067
return fn();
10711068
} finally {
10721069
setCurrentUpdatePriority(previousPriority);
1073-
ReactCurrentBatchConfig.transition = prevTransition;
10741070
}
10751071
}
10761072

@@ -1114,14 +1110,11 @@ export function discreteUpdates<A, B, C, D, R>(
11141110
d: D,
11151111
): R {
11161112
const previousPriority = getCurrentUpdatePriority();
1117-
const prevTransition = ReactCurrentBatchConfig.transition;
11181113
try {
1119-
ReactCurrentBatchConfig.transition = 0;
11201114
setCurrentUpdatePriority(DiscreteEventPriority);
11211115
return fn(a, b, c, d);
11221116
} finally {
11231117
setCurrentUpdatePriority(previousPriority);
1124-
ReactCurrentBatchConfig.transition = prevTransition;
11251118
if (executionContext === NoContext) {
11261119
resetRenderTimer();
11271120
}
@@ -1151,10 +1144,8 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11511144
const prevExecutionContext = executionContext;
11521145
executionContext |= BatchedContext;
11531146

1154-
const prevTransition = ReactCurrentBatchConfig.transition;
11551147
const previousPriority = getCurrentUpdatePriority();
11561148
try {
1157-
ReactCurrentBatchConfig.transition = 0;
11581149
setCurrentUpdatePriority(DiscreteEventPriority);
11591150
if (fn) {
11601151
return fn(a);
@@ -1163,7 +1154,6 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11631154
}
11641155
} finally {
11651156
setCurrentUpdatePriority(previousPriority);
1166-
ReactCurrentBatchConfig.transition = prevTransition;
11671157
executionContext = prevExecutionContext;
11681158
// Flush the immediate callbacks that were scheduled during this batch.
11691159
// Note that this will happen even if batchedUpdates is higher up
@@ -1185,15 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11851175
export function flushControlled(fn: () => mixed): void {
11861176
const prevExecutionContext = executionContext;
11871177
executionContext |= BatchedContext;
1188-
const prevTransition = ReactCurrentBatchConfig.transition;
11891178
const previousPriority = getCurrentUpdatePriority();
11901179
try {
1191-
ReactCurrentBatchConfig.transition = 0;
11921180
setCurrentUpdatePriority(DiscreteEventPriority);
11931181
fn();
11941182
} finally {
11951183
setCurrentUpdatePriority(previousPriority);
1196-
ReactCurrentBatchConfig.transition = prevTransition;
11971184

11981185
executionContext = prevExecutionContext;
11991186
if (executionContext === NoContext) {
@@ -1688,13 +1675,10 @@ function commitRoot(root) {
16881675
// TODO: This no longer makes any sense. We already wrap the mutation and
16891676
// layout phases. Should be able to remove.
16901677
const previousUpdateLanePriority = getCurrentUpdatePriority();
1691-
const prevTransition = ReactCurrentBatchConfig.transition;
16921678
try {
1693-
ReactCurrentBatchConfig.transition = 0;
16941679
setCurrentUpdatePriority(DiscreteEventPriority);
16951680
commitRootImpl(root, previousUpdateLanePriority);
16961681
} finally {
1697-
ReactCurrentBatchConfig.transition = prevTransition;
16981682
setCurrentUpdatePriority(previousUpdateLanePriority);
16991683
}
17001684

@@ -1816,8 +1800,6 @@ function commitRootImpl(root, renderPriorityLevel) {
18161800
NoFlags;
18171801

18181802
if (subtreeHasEffects || rootHasEffect) {
1819-
const prevTransition = ReactCurrentBatchConfig.transition;
1820-
ReactCurrentBatchConfig.transition = 0;
18211803
const previousPriority = getCurrentUpdatePriority();
18221804
setCurrentUpdatePriority(DiscreteEventPriority);
18231805

@@ -1899,7 +1881,6 @@ function commitRootImpl(root, renderPriorityLevel) {
18991881

19001882
// Reset the priority to the previous non-sync value.
19011883
setCurrentUpdatePriority(previousPriority);
1902-
ReactCurrentBatchConfig.transition = prevTransition;
19031884
} else {
19041885
// No effects.
19051886
root.current = finishedWork;
@@ -2036,15 +2017,12 @@ export function flushPassiveEffects(): boolean {
20362017
if (rootWithPendingPassiveEffects !== null) {
20372018
const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
20382019
const priority = lowerEventPriority(DefaultEventPriority, renderPriority);
2039-
const prevTransition = ReactCurrentBatchConfig.transition;
20402020
const previousPriority = getCurrentUpdatePriority();
20412021
try {
2042-
ReactCurrentBatchConfig.transition = 0;
20432022
setCurrentUpdatePriority(priority);
20442023
return flushPassiveEffectsImpl();
20452024
} finally {
20462025
setCurrentUpdatePriority(previousPriority);
2047-
ReactCurrentBatchConfig.transition = prevTransition;
20482026
}
20492027
}
20502028
return false;

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

-22
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ const ceil = Math.ceil;
245245
const {
246246
ReactCurrentDispatcher,
247247
ReactCurrentOwner,
248-
ReactCurrentBatchConfig,
249248
IsSomeRendererActing,
250249
} = ReactSharedInternals;
251250

@@ -1063,14 +1062,11 @@ export function flushDiscreteUpdates() {
10631062

10641063
export function deferredUpdates<A>(fn: () => A): A {
10651064
const previousPriority = getCurrentUpdatePriority();
1066-
const prevTransition = ReactCurrentBatchConfig.transition;
10671065
try {
1068-
ReactCurrentBatchConfig.transition = 0;
10691066
setCurrentUpdatePriority(DefaultEventPriority);
10701067
return fn();
10711068
} finally {
10721069
setCurrentUpdatePriority(previousPriority);
1073-
ReactCurrentBatchConfig.transition = prevTransition;
10741070
}
10751071
}
10761072

@@ -1114,14 +1110,11 @@ export function discreteUpdates<A, B, C, D, R>(
11141110
d: D,
11151111
): R {
11161112
const previousPriority = getCurrentUpdatePriority();
1117-
const prevTransition = ReactCurrentBatchConfig.transition;
11181113
try {
1119-
ReactCurrentBatchConfig.transition = 0;
11201114
setCurrentUpdatePriority(DiscreteEventPriority);
11211115
return fn(a, b, c, d);
11221116
} finally {
11231117
setCurrentUpdatePriority(previousPriority);
1124-
ReactCurrentBatchConfig.transition = prevTransition;
11251118
if (executionContext === NoContext) {
11261119
resetRenderTimer();
11271120
}
@@ -1151,10 +1144,8 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11511144
const prevExecutionContext = executionContext;
11521145
executionContext |= BatchedContext;
11531146

1154-
const prevTransition = ReactCurrentBatchConfig.transition;
11551147
const previousPriority = getCurrentUpdatePriority();
11561148
try {
1157-
ReactCurrentBatchConfig.transition = 0;
11581149
setCurrentUpdatePriority(DiscreteEventPriority);
11591150
if (fn) {
11601151
return fn(a);
@@ -1163,7 +1154,6 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11631154
}
11641155
} finally {
11651156
setCurrentUpdatePriority(previousPriority);
1166-
ReactCurrentBatchConfig.transition = prevTransition;
11671157
executionContext = prevExecutionContext;
11681158
// Flush the immediate callbacks that were scheduled during this batch.
11691159
// Note that this will happen even if batchedUpdates is higher up
@@ -1185,15 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11851175
export function flushControlled(fn: () => mixed): void {
11861176
const prevExecutionContext = executionContext;
11871177
executionContext |= BatchedContext;
1188-
const prevTransition = ReactCurrentBatchConfig.transition;
11891178
const previousPriority = getCurrentUpdatePriority();
11901179
try {
1191-
ReactCurrentBatchConfig.transition = 0;
11921180
setCurrentUpdatePriority(DiscreteEventPriority);
11931181
fn();
11941182
} finally {
11951183
setCurrentUpdatePriority(previousPriority);
1196-
ReactCurrentBatchConfig.transition = prevTransition;
11971184

11981185
executionContext = prevExecutionContext;
11991186
if (executionContext === NoContext) {
@@ -1688,13 +1675,10 @@ function commitRoot(root) {
16881675
// TODO: This no longer makes any sense. We already wrap the mutation and
16891676
// layout phases. Should be able to remove.
16901677
const previousUpdateLanePriority = getCurrentUpdatePriority();
1691-
const prevTransition = ReactCurrentBatchConfig.transition;
16921678
try {
1693-
ReactCurrentBatchConfig.transition = 0;
16941679
setCurrentUpdatePriority(DiscreteEventPriority);
16951680
commitRootImpl(root, previousUpdateLanePriority);
16961681
} finally {
1697-
ReactCurrentBatchConfig.transition = prevTransition;
16981682
setCurrentUpdatePriority(previousUpdateLanePriority);
16991683
}
17001684

@@ -1816,8 +1800,6 @@ function commitRootImpl(root, renderPriorityLevel) {
18161800
NoFlags;
18171801

18181802
if (subtreeHasEffects || rootHasEffect) {
1819-
const prevTransition = ReactCurrentBatchConfig.transition;
1820-
ReactCurrentBatchConfig.transition = 0;
18211803
const previousPriority = getCurrentUpdatePriority();
18221804
setCurrentUpdatePriority(DiscreteEventPriority);
18231805

@@ -1899,7 +1881,6 @@ function commitRootImpl(root, renderPriorityLevel) {
18991881

19001882
// Reset the priority to the previous non-sync value.
19011883
setCurrentUpdatePriority(previousPriority);
1902-
ReactCurrentBatchConfig.transition = prevTransition;
19031884
} else {
19041885
// No effects.
19051886
root.current = finishedWork;
@@ -2036,15 +2017,12 @@ export function flushPassiveEffects(): boolean {
20362017
if (rootWithPendingPassiveEffects !== null) {
20372018
const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
20382019
const priority = lowerEventPriority(DefaultEventPriority, renderPriority);
2039-
const prevTransition = ReactCurrentBatchConfig.transition;
20402020
const previousPriority = getCurrentUpdatePriority();
20412021
try {
2042-
ReactCurrentBatchConfig.transition = 0;
20432022
setCurrentUpdatePriority(priority);
20442023
return flushPassiveEffectsImpl();
20452024
} finally {
20462025
setCurrentUpdatePriority(previousPriority);
2047-
ReactCurrentBatchConfig.transition = prevTransition;
20482026
}
20492027
}
20502028
return false;

packages/react-reconciler/src/__tests__/ReactFlushSync-test.js

-43
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ let ReactNoop;
33
let Scheduler;
44
let useState;
55
let useEffect;
6-
let startTransition;
76

87
describe('ReactFlushSync', () => {
98
beforeEach(() => {
@@ -14,7 +13,6 @@ describe('ReactFlushSync', () => {
1413
Scheduler = require('scheduler');
1514
useState = React.useState;
1615
useEffect = React.useEffect;
17-
startTransition = React.unstable_startTransition;
1816
});
1917

2018
function Text({text}) {
@@ -64,47 +62,6 @@ describe('ReactFlushSync', () => {
6462
expect(root).toMatchRenderedOutput('1, 1');
6563
});
6664

67-
// @gate experimental
68-
test('nested with startTransition', async () => {
69-
let setSyncState;
70-
let setState;
71-
function App() {
72-
const [syncState, _setSyncState] = useState(0);
73-
const [state, _setState] = useState(0);
74-
setSyncState = _setSyncState;
75-
setState = _setState;
76-
return <Text text={`${syncState}, ${state}`} />;
77-
}
78-
79-
const root = ReactNoop.createRoot();
80-
await ReactNoop.act(async () => {
81-
root.render(<App />);
82-
});
83-
expect(Scheduler).toHaveYielded(['0, 0']);
84-
expect(root).toMatchRenderedOutput('0, 0');
85-
86-
await ReactNoop.act(async () => {
87-
ReactNoop.flushSync(() => {
88-
startTransition(() => {
89-
// This should be async even though flushSync is on the stack, because
90-
// startTransition is closer.
91-
setState(1);
92-
ReactNoop.flushSync(() => {
93-
// This should be async even though startTransition is on the stack,
94-
// because flushSync is closer.
95-
setSyncState(1);
96-
});
97-
});
98-
});
99-
// Only the sync update should have flushed
100-
expect(Scheduler).toHaveYielded(['1, 0']);
101-
expect(root).toMatchRenderedOutput('1, 0');
102-
});
103-
// Now the async update has flushed, too.
104-
expect(Scheduler).toHaveYielded(['1, 1']);
105-
expect(root).toMatchRenderedOutput('1, 1');
106-
});
107-
10865
test('flushes passive effects synchronously when they are the result of a sync render', async () => {
10966
function App() {
11067
useEffect(() => {

0 commit comments

Comments
 (0)