Skip to content

Commit 92fcd46

Browse files
authoredAug 28, 2020
Replace SuspenseConfig object with an integer (#19706)
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 b754caa commit 92fcd46

15 files changed

+80
-108
lines changed
 

‎packages/react-debug-tools/src/ReactDebugHooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
} from 'react-reconciler/src/ReactInternalTypes';
2121
import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
2222

23-
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig';
23+
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberTransition';
2424
import {NoMode} from 'react-reconciler/src/ReactTypeOfMode';
2525

2626
import ErrorStackParser from 'error-stack-parser';

‎packages/react-dom/src/server/ReactPartialRendererHooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
MutableSourceSubscribeFn,
1616
ReactContext,
1717
} from 'shared/ReactTypes';
18-
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberSuspenseConfig';
18+
import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberTransition';
1919
import type PartialRenderer from './ReactPartialRenderer';
2020

2121
import {validateContextBounds} from './ReactPartialRendererContext';

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

+3-7
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

+3-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
requestUpdateLane,
5757
scheduleUpdateOnFiber,
5858
} from './ReactFiberWorkLoop.old';
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/ReactFiberHooks.new.js

+19-23
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

+19-23
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';
@@ -69,7 +69,6 @@ import invariant from 'shared/invariant';
6969
import getComponentName from 'shared/getComponentName';
7070
import is from 'shared/objectIs';
7171
import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.old';
72-
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
7372
import {
7473
UserBlockingPriority,
7574
NormalPriority,
@@ -1002,8 +1001,7 @@ function useMutableSource<Source, Snapshot>(
10021001
if (!is(snapshot, maybeNewSnapshot)) {
10031002
setSnapshot(maybeNewSnapshot);
10041003

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

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

10291026
markRootMutableRead(root, lane);
10301027
} catch (error) {
@@ -1440,12 +1437,12 @@ function mountDeferredValue<T>(
14401437
): T {
14411438
const [prevValue, setValue] = mountState(value);
14421439
mountEffect(() => {
1443-
const previousConfig = ReactCurrentBatchConfig.suspense;
1444-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1440+
const prevTransition = ReactCurrentBatchConfig.transition;
1441+
ReactCurrentBatchConfig.transition = 1;
14451442
try {
14461443
setValue(value);
14471444
} finally {
1448-
ReactCurrentBatchConfig.suspense = previousConfig;
1445+
ReactCurrentBatchConfig.transition = prevTransition;
14491446
}
14501447
}, [value, config]);
14511448
return prevValue;
@@ -1457,12 +1454,12 @@ function updateDeferredValue<T>(
14571454
): T {
14581455
const [prevValue, setValue] = updateState(value);
14591456
updateEffect(() => {
1460-
const previousConfig = ReactCurrentBatchConfig.suspense;
1461-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1457+
const prevTransition = ReactCurrentBatchConfig.transition;
1458+
ReactCurrentBatchConfig.transition = 1;
14621459
try {
14631460
setValue(value);
14641461
} finally {
1465-
ReactCurrentBatchConfig.suspense = previousConfig;
1462+
ReactCurrentBatchConfig.transition = prevTransition;
14661463
}
14671464
}, [value, config]);
14681465
return prevValue;
@@ -1474,12 +1471,12 @@ function rerenderDeferredValue<T>(
14741471
): T {
14751472
const [prevValue, setValue] = rerenderState(value);
14761473
updateEffect(() => {
1477-
const previousConfig = ReactCurrentBatchConfig.suspense;
1478-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1474+
const prevTransition = ReactCurrentBatchConfig.transition;
1475+
ReactCurrentBatchConfig.transition = 1;
14791476
try {
14801477
setValue(value);
14811478
} finally {
1482-
ReactCurrentBatchConfig.suspense = previousConfig;
1479+
ReactCurrentBatchConfig.transition = prevTransition;
14831480
}
14841481
}, [value, config]);
14851482
return prevValue;
@@ -1508,16 +1505,16 @@ function startTransition(setPending, config, callback) {
15081505
runWithPriority(
15091506
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15101507
() => {
1511-
const previousConfig = ReactCurrentBatchConfig.suspense;
1512-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1508+
const prevTransition = ReactCurrentBatchConfig.transition;
1509+
ReactCurrentBatchConfig.transition = 1;
15131510
try {
15141511
setPending(false);
15151512
callback();
15161513
} finally {
15171514
if (decoupleUpdatePriorityFromScheduler) {
15181515
setCurrentUpdateLanePriority(previousLanePriority);
15191516
}
1520-
ReactCurrentBatchConfig.suspense = previousConfig;
1517+
ReactCurrentBatchConfig.transition = prevTransition;
15211518
}
15221519
},
15231520
);
@@ -1534,13 +1531,13 @@ function startTransition(setPending, config, callback) {
15341531
runWithPriority(
15351532
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
15361533
() => {
1537-
const previousConfig = ReactCurrentBatchConfig.suspense;
1538-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1534+
const prevTransition = ReactCurrentBatchConfig.transition;
1535+
ReactCurrentBatchConfig.transition = 1;
15391536
try {
15401537
setPending(false);
15411538
callback();
15421539
} finally {
1543-
ReactCurrentBatchConfig.suspense = previousConfig;
1540+
ReactCurrentBatchConfig.transition = prevTransition;
15441541
}
15451542
},
15461543
);
@@ -1683,8 +1680,7 @@ function dispatchAction<S, A>(
16831680
}
16841681

16851682
const eventTime = requestEventTime();
1686-
const suspenseConfig = requestCurrentSuspenseConfig();
1687-
const lane = requestUpdateLane(fiber, suspenseConfig);
1683+
const lane = requestUpdateLane(fiber);
16881684

16891685
const update: Update<S, A> = {
16901686
lane,

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

+2-4
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)