Skip to content

Commit e80d38b

Browse files
committed
Replace SuspenseConfig object with an integer
Now that the options in SuspenseConfig are no longer supported, the only thing we use it for is to track whether an update is part of a transition. I've renamed `ReactCurrentBatchConfig.suspense` to `ReactCurrentBatchConfig.transition` and changed the type to a number. The number is always either 0 or 1. I could have made it a boolean; however, most likely this will eventually be either a Lane or an incrementing identifier. The `withSuspenseConfig` export still exists until we've removed all the callers from www.
1 parent 9391eb7 commit e80d38b

12 files changed

+97
-100
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
requestUpdateLane,
5757
scheduleUpdateOnFiber,
5858
} from './ReactFiberWorkLoop.new';
59-
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
6059
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
6160

6261
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
@@ -196,8 +195,7 @@ const classComponentUpdater = {
196195
enqueueSetState(inst, payload, callback) {
197196
const fiber = getInstance(inst);
198197
const eventTime = requestEventTime();
199-
const suspenseConfig = requestCurrentSuspenseConfig();
200-
const lane = requestUpdateLane(fiber, suspenseConfig);
198+
const lane = requestUpdateLane(fiber);
201199

202200
const update = createUpdate(eventTime, lane);
203201
update.payload = payload;
@@ -227,8 +225,7 @@ const classComponentUpdater = {
227225
enqueueReplaceState(inst, payload, callback) {
228226
const fiber = getInstance(inst);
229227
const eventTime = requestEventTime();
230-
const suspenseConfig = requestCurrentSuspenseConfig();
231-
const lane = requestUpdateLane(fiber, suspenseConfig);
228+
const lane = requestUpdateLane(fiber);
232229

233230
const update = createUpdate(eventTime, lane);
234231
update.tag = ReplaceState;
@@ -260,8 +257,7 @@ const classComponentUpdater = {
260257
enqueueForceUpdate(inst, callback) {
261258
const fiber = getInstance(inst);
262259
const eventTime = requestEventTime();
263-
const suspenseConfig = requestCurrentSuspenseConfig();
264-
const lane = requestUpdateLane(fiber, suspenseConfig);
260+
const lane = requestUpdateLane(fiber);
265261

266262
const update = createUpdate(eventTime, lane);
267263
update.tag = ForceUpdate;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ import {
5555
requestEventTime,
5656
requestUpdateLane,
5757
scheduleUpdateOnFiber,
58+
<<<<<<< packages/react-reconciler/src/ReactFiberClassComponent.old.js
5859
} from './ReactFiberWorkLoop.old';
5960
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
61+
=======
62+
} from './ReactFiberWorkLoop.new';
63+
>>>>>>> packages/react-reconciler/src/ReactFiberClassComponent.new.js
6064
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
6165

6266
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
@@ -196,8 +200,7 @@ const classComponentUpdater = {
196200
enqueueSetState(inst, payload, callback) {
197201
const fiber = getInstance(inst);
198202
const eventTime = requestEventTime();
199-
const suspenseConfig = requestCurrentSuspenseConfig();
200-
const lane = requestUpdateLane(fiber, suspenseConfig);
203+
const lane = requestUpdateLane(fiber);
201204

202205
const update = createUpdate(eventTime, lane);
203206
update.payload = payload;
@@ -227,8 +230,7 @@ const classComponentUpdater = {
227230
enqueueReplaceState(inst, payload, callback) {
228231
const fiber = getInstance(inst);
229232
const eventTime = requestEventTime();
230-
const suspenseConfig = requestCurrentSuspenseConfig();
231-
const lane = requestUpdateLane(fiber, suspenseConfig);
233+
const lane = requestUpdateLane(fiber);
232234

233235
const update = createUpdate(eventTime, lane);
234236
update.tag = ReplaceState;
@@ -260,8 +262,7 @@ const classComponentUpdater = {
260262
enqueueForceUpdate(inst, callback) {
261263
const fiber = getInstance(inst);
262264
const eventTime = requestEventTime();
263-
const suspenseConfig = requestCurrentSuspenseConfig();
264-
const lane = requestUpdateLane(fiber, suspenseConfig);
265+
const lane = requestUpdateLane(fiber);
265266

266267
const update = createUpdate(eventTime, lane);
267268
update.tag = ForceUpdate;

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
import type {Fiber, Dispatcher} from './ReactInternalTypes';
1717
import type {Lanes, Lane} from './ReactFiberLane';
1818
import type {HookEffectTag} from './ReactHookEffectTags';
19-
import type {SuspenseConfig} from './ReactFiberSuspenseConfig';
19+
import type {SuspenseConfig} from './ReactFiberTransition';
2020
import type {ReactPriorityLevel} from './ReactInternalTypes';
2121
import type {FiberRoot} from './ReactInternalTypes';
2222
import type {OpaqueIDType} from './ReactFiberHostConfig';
@@ -70,7 +70,6 @@ import invariant from 'shared/invariant';
7070
import getComponentName from 'shared/getComponentName';
7171
import is from 'shared/objectIs';
7272
import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.new';
73-
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
7473
import {
7574
UserBlockingPriority,
7675
NormalPriority,
@@ -1003,8 +1002,7 @@ function useMutableSource<Source, Snapshot>(
10031002
if (!is(snapshot, maybeNewSnapshot)) {
10041003
setSnapshot(maybeNewSnapshot);
10051004

1006-
const suspenseConfig = requestCurrentSuspenseConfig();
1007-
const lane = requestUpdateLane(fiber, suspenseConfig);
1005+
const lane = requestUpdateLane(fiber);
10081006
markRootMutableRead(root, lane);
10091007
}
10101008
// If the source mutated between render and now,
@@ -1024,8 +1022,7 @@ function useMutableSource<Source, Snapshot>(
10241022
latestSetSnapshot(latestGetSnapshot(source._source));
10251023

10261024
// Record a pending mutable source update with the same expiration time.
1027-
const suspenseConfig = requestCurrentSuspenseConfig();
1028-
const lane = requestUpdateLane(fiber, suspenseConfig);
1025+
const lane = requestUpdateLane(fiber);
10291026

10301027
markRootMutableRead(root, lane);
10311028
} catch (error) {
@@ -1441,12 +1438,12 @@ function mountDeferredValue<T>(
14411438
): T {
14421439
const [prevValue, setValue] = mountState(value);
14431440
mountEffect(() => {
1444-
const previousConfig = ReactCurrentBatchConfig.suspense;
1445-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1441+
const prevTransition = ReactCurrentBatchConfig.transition;
1442+
ReactCurrentBatchConfig.transition = 1;
14461443
try {
14471444
setValue(value);
14481445
} finally {
1449-
ReactCurrentBatchConfig.suspense = previousConfig;
1446+
ReactCurrentBatchConfig.transition = prevTransition;
14501447
}
14511448
}, [value, config]);
14521449
return prevValue;
@@ -1458,12 +1455,12 @@ function updateDeferredValue<T>(
14581455
): T {
14591456
const [prevValue, setValue] = updateState(value);
14601457
updateEffect(() => {
1461-
const previousConfig = ReactCurrentBatchConfig.suspense;
1462-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1458+
const prevTransition = ReactCurrentBatchConfig.transition;
1459+
ReactCurrentBatchConfig.transition = 1;
14631460
try {
14641461
setValue(value);
14651462
} finally {
1466-
ReactCurrentBatchConfig.suspense = previousConfig;
1463+
ReactCurrentBatchConfig.transition = prevTransition;
14671464
}
14681465
}, [value, config]);
14691466
return prevValue;
@@ -1475,12 +1472,12 @@ function rerenderDeferredValue<T>(
14751472
): T {
14761473
const [prevValue, setValue] = rerenderState(value);
14771474
updateEffect(() => {
1478-
const previousConfig = ReactCurrentBatchConfig.suspense;
1479-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1475+
const prevTransition = ReactCurrentBatchConfig.transition;
1476+
ReactCurrentBatchConfig.transition = 1;
14801477
try {
14811478
setValue(value);
14821479
} finally {
1483-
ReactCurrentBatchConfig.suspense = previousConfig;
1480+
ReactCurrentBatchConfig.transition = prevTransition;
14841481
}
14851482
}, [value, config]);
14861483
return prevValue;
@@ -1509,16 +1506,16 @@ function startTransition(setPending, config, callback) {
15091506
runWithPriority(
15101507
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15111508
() => {
1512-
const previousConfig = ReactCurrentBatchConfig.suspense;
1513-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1509+
const prevTransition = ReactCurrentBatchConfig.transition;
1510+
ReactCurrentBatchConfig.transition = 1;
15141511
try {
15151512
setPending(false);
15161513
callback();
15171514
} finally {
15181515
if (decoupleUpdatePriorityFromScheduler) {
15191516
setCurrentUpdateLanePriority(previousLanePriority);
15201517
}
1521-
ReactCurrentBatchConfig.suspense = previousConfig;
1518+
ReactCurrentBatchConfig.transition = prevTransition;
15221519
}
15231520
},
15241521
);
@@ -1535,13 +1532,13 @@ function startTransition(setPending, config, callback) {
15351532
runWithPriority(
15361533
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15371534
() => {
1538-
const previousConfig = ReactCurrentBatchConfig.suspense;
1539-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1535+
const prevTransition = ReactCurrentBatchConfig.transition;
1536+
ReactCurrentBatchConfig.transition = 1;
15401537
try {
15411538
setPending(false);
15421539
callback();
15431540
} finally {
1544-
ReactCurrentBatchConfig.suspense = previousConfig;
1541+
ReactCurrentBatchConfig.transition = prevTransition;
15451542
}
15461543
},
15471544
);
@@ -1685,8 +1682,7 @@ function dispatchAction<S, A>(
16851682
}
16861683

16871684
const eventTime = requestEventTime();
1688-
const suspenseConfig = requestCurrentSuspenseConfig();
1689-
const lane = requestUpdateLane(fiber, suspenseConfig);
1685+
const lane = requestUpdateLane(fiber);
16901686

16911687
const update: Update<S, A> = {
16921688
lane,

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
import type {Fiber, Dispatcher} from './ReactInternalTypes';
1717
import type {Lanes, Lane} from './ReactFiberLane';
1818
import type {HookEffectTag} from './ReactHookEffectTags';
19-
import type {SuspenseConfig} from './ReactFiberSuspenseConfig';
19+
import type {SuspenseConfig} from './ReactFiberTransition';
2020
import type {ReactPriorityLevel} from './ReactInternalTypes';
2121
import type {FiberRoot} from './ReactInternalTypes';
2222
import type {OpaqueIDType} from './ReactFiberHostConfig';
@@ -68,8 +68,12 @@ import {
6868
import invariant from 'shared/invariant';
6969
import getComponentName from 'shared/getComponentName';
7070
import is from 'shared/objectIs';
71+
<<<<<<< packages/react-reconciler/src/ReactFiberHooks.old.js
7172
import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.old';
7273
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
74+
=======
75+
import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.new';
76+
>>>>>>> packages/react-reconciler/src/ReactFiberHooks.new.js
7377
import {
7478
UserBlockingPriority,
7579
NormalPriority,
@@ -1002,8 +1006,7 @@ function useMutableSource<Source, Snapshot>(
10021006
if (!is(snapshot, maybeNewSnapshot)) {
10031007
setSnapshot(maybeNewSnapshot);
10041008

1005-
const suspenseConfig = requestCurrentSuspenseConfig();
1006-
const lane = requestUpdateLane(fiber, suspenseConfig);
1009+
const lane = requestUpdateLane(fiber);
10071010
markRootMutableRead(root, lane);
10081011
}
10091012
// If the source mutated between render and now,
@@ -1023,8 +1026,7 @@ function useMutableSource<Source, Snapshot>(
10231026
latestSetSnapshot(latestGetSnapshot(source._source));
10241027

10251028
// Record a pending mutable source update with the same expiration time.
1026-
const suspenseConfig = requestCurrentSuspenseConfig();
1027-
const lane = requestUpdateLane(fiber, suspenseConfig);
1029+
const lane = requestUpdateLane(fiber);
10281030

10291031
markRootMutableRead(root, lane);
10301032
} catch (error) {
@@ -1440,12 +1442,12 @@ function mountDeferredValue<T>(
14401442
): T {
14411443
const [prevValue, setValue] = mountState(value);
14421444
mountEffect(() => {
1443-
const previousConfig = ReactCurrentBatchConfig.suspense;
1444-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1445+
const prevTransition = ReactCurrentBatchConfig.transition;
1446+
ReactCurrentBatchConfig.transition = 1;
14451447
try {
14461448
setValue(value);
14471449
} finally {
1448-
ReactCurrentBatchConfig.suspense = previousConfig;
1450+
ReactCurrentBatchConfig.transition = prevTransition;
14491451
}
14501452
}, [value, config]);
14511453
return prevValue;
@@ -1457,12 +1459,12 @@ function updateDeferredValue<T>(
14571459
): T {
14581460
const [prevValue, setValue] = updateState(value);
14591461
updateEffect(() => {
1460-
const previousConfig = ReactCurrentBatchConfig.suspense;
1461-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1462+
const prevTransition = ReactCurrentBatchConfig.transition;
1463+
ReactCurrentBatchConfig.transition = 1;
14621464
try {
14631465
setValue(value);
14641466
} finally {
1465-
ReactCurrentBatchConfig.suspense = previousConfig;
1467+
ReactCurrentBatchConfig.transition = prevTransition;
14661468
}
14671469
}, [value, config]);
14681470
return prevValue;
@@ -1474,12 +1476,12 @@ function rerenderDeferredValue<T>(
14741476
): T {
14751477
const [prevValue, setValue] = rerenderState(value);
14761478
updateEffect(() => {
1477-
const previousConfig = ReactCurrentBatchConfig.suspense;
1478-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1479+
const prevTransition = ReactCurrentBatchConfig.transition;
1480+
ReactCurrentBatchConfig.transition = 1;
14791481
try {
14801482
setValue(value);
14811483
} finally {
1482-
ReactCurrentBatchConfig.suspense = previousConfig;
1484+
ReactCurrentBatchConfig.transition = prevTransition;
14831485
}
14841486
}, [value, config]);
14851487
return prevValue;
@@ -1508,16 +1510,16 @@ function startTransition(setPending, config, callback) {
15081510
runWithPriority(
15091511
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15101512
() => {
1511-
const previousConfig = ReactCurrentBatchConfig.suspense;
1512-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1513+
const prevTransition = ReactCurrentBatchConfig.transition;
1514+
ReactCurrentBatchConfig.transition = 1;
15131515
try {
15141516
setPending(false);
15151517
callback();
15161518
} finally {
15171519
if (decoupleUpdatePriorityFromScheduler) {
15181520
setCurrentUpdateLanePriority(previousLanePriority);
15191521
}
1520-
ReactCurrentBatchConfig.suspense = previousConfig;
1522+
ReactCurrentBatchConfig.transition = prevTransition;
15211523
}
15221524
},
15231525
);
@@ -1534,13 +1536,13 @@ function startTransition(setPending, config, callback) {
15341536
runWithPriority(
15351537
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15361538
() => {
1537-
const previousConfig = ReactCurrentBatchConfig.suspense;
1538-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1539+
const prevTransition = ReactCurrentBatchConfig.transition;
1540+
ReactCurrentBatchConfig.transition = 1;
15391541
try {
15401542
setPending(false);
15411543
callback();
15421544
} finally {
1543-
ReactCurrentBatchConfig.suspense = previousConfig;
1545+
ReactCurrentBatchConfig.transition = prevTransition;
15441546
}
15451547
},
15461548
);
@@ -1683,8 +1685,7 @@ function dispatchAction<S, A>(
16831685
}
16841686

16851687
const eventTime = requestEventTime();
1686-
const suspenseConfig = requestCurrentSuspenseConfig();
1687-
const lane = requestUpdateLane(fiber, suspenseConfig);
1688+
const lane = requestUpdateLane(fiber);
16881689

16891690
const update: Update<S, A> = {
16901691
lane,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ import {
8383
getCurrentUpdateLanePriority,
8484
setCurrentUpdateLanePriority,
8585
} from './ReactFiberLane';
86-
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
8786
import {
8887
scheduleRefresh,
8988
scheduleRoot,
@@ -266,8 +265,7 @@ export function updateContainer(
266265
warnIfNotScopedWithMatchingAct(current);
267266
}
268267
}
269-
const suspenseConfig = requestCurrentSuspenseConfig();
270-
const lane = requestUpdateLane(current, suspenseConfig);
268+
const lane = requestUpdateLane(current);
271269

272270
if (enableSchedulingProfiler) {
273271
markRenderScheduled(lane);
@@ -427,7 +425,7 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void {
427425
return;
428426
}
429427
const eventTime = requestEventTime();
430-
const lane = requestUpdateLane(fiber, null);
428+
const lane = requestUpdateLane(fiber);
431429
scheduleUpdateOnFiber(fiber, lane, eventTime);
432430
markRetryLaneIfNotHydrated(fiber, lane);
433431
}

0 commit comments

Comments
 (0)