@@ -16,7 +16,6 @@ import type {
16
16
import type { Fiber , Dispatcher } from './ReactInternalTypes' ;
17
17
import type { Lanes , Lane } from './ReactFiberLane' ;
18
18
import type { HookEffectTag } from './ReactHookEffectTags' ;
19
- import type { SuspenseConfig } from './ReactFiberTransition' ;
20
19
import type { ReactPriorityLevel } from './ReactInternalTypes' ;
21
20
import type { FiberRoot } from './ReactInternalTypes' ;
22
21
import type { OpaqueIDType } from './ReactFiberHostConfig' ;
@@ -151,10 +150,6 @@ export type Effect = {|
151
150
152
151
export type FunctionComponentUpdateQueue = { | lastEffect : Effect | null | } ;
153
152
154
- type TimeoutConfig = { |
155
- timeoutMs : number ,
156
- | } ;
157
-
158
153
type BasicStateAction < S > = ( S => S ) | S ;
159
154
160
155
type Dispatch < A > = A => void ;
@@ -1432,10 +1427,7 @@ function updateMemo<T>(
1432
1427
return nextValue;
1433
1428
}
1434
1429
1435
- function mountDeferredValue < T > (
1436
- value: T,
1437
- config: TimeoutConfig | void | null,
1438
- ): T {
1430
+ function mountDeferredValue < T > (value: T): T {
1439
1431
const [ prevValue , setValue ] = mountState ( value ) ;
1440
1432
mountEffect ( ( ) => {
1441
1433
const prevTransition = ReactCurrentBatchConfig . transition ;
@@ -1445,14 +1437,11 @@ function mountDeferredValue<T>(
1445
1437
} finally {
1446
1438
ReactCurrentBatchConfig . transition = prevTransition ;
1447
1439
}
1448
- } , [ value , config ] ) ;
1440
+ } , [ value ] ) ;
1449
1441
return prevValue ;
1450
1442
}
1451
1443
1452
- function updateDeferredValue< T > (
1453
- value: T,
1454
- config: TimeoutConfig | void | null,
1455
- ): T {
1444
+ function updateDeferredValue< T > (value: T): T {
1456
1445
const [ prevValue , setValue ] = updateState ( value ) ;
1457
1446
updateEffect ( ( ) => {
1458
1447
const prevTransition = ReactCurrentBatchConfig . transition ;
@@ -1462,14 +1451,11 @@ function updateDeferredValue<T>(
1462
1451
} finally {
1463
1452
ReactCurrentBatchConfig . transition = prevTransition ;
1464
1453
}
1465
- } , [ value , config ] ) ;
1454
+ } , [ value ] ) ;
1466
1455
return prevValue ;
1467
1456
}
1468
1457
1469
- function rerenderDeferredValue< T > (
1470
- value: T,
1471
- config: TimeoutConfig | void | null,
1472
- ): T {
1458
+ function rerenderDeferredValue< T > (value: T): T {
1473
1459
const [ prevValue , setValue ] = rerenderState ( value ) ;
1474
1460
updateEffect ( ( ) => {
1475
1461
const prevTransition = ReactCurrentBatchConfig . transition ;
@@ -1479,11 +1465,11 @@ function rerenderDeferredValue<T>(
1479
1465
} finally {
1480
1466
ReactCurrentBatchConfig . transition = prevTransition ;
1481
1467
}
1482
- } , [ value , config ] ) ;
1468
+ } , [ value ] ) ;
1483
1469
return prevValue ;
1484
1470
}
1485
1471
1486
- function startTransition(setPending, config, callback) {
1472
+ function startTransition(setPending, callback) {
1487
1473
const priorityLevel = getCurrentPriorityLevel ( ) ;
1488
1474
if ( decoupleUpdatePriorityFromScheduler ) {
1489
1475
const previousLanePriority = getCurrentUpdateLanePriority ( ) ;
@@ -1500,7 +1486,9 @@ function startTransition(setPending, config, callback) {
1500
1486
} ,
1501
1487
) ;
1502
1488
1503
- // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1489
+ // TODO: Can remove this. Was only necessary because we used to give
1490
+ // different behavior to transitions without a config object. Now they are
1491
+ // all treated the same.
1504
1492
setCurrentUpdateLanePriority ( DefaultLanePriority ) ;
1505
1493
1506
1494
runWithPriority (
@@ -1545,36 +1533,26 @@ function startTransition(setPending, config, callback) {
1545
1533
}
1546
1534
}
1547
1535
1548
- function mountTransition (
1549
- config : SuspenseConfig | void | null ,
1550
- ) : [ ( ( ) => void ) => void , boolean ] {
1536
+ function mountTransition ( ) : [ ( ( ) => void ) => void , boolean ] {
1551
1537
const [ isPending , setPending ] = mountState ( false ) ;
1552
- const start = mountCallback ( startTransition . bind ( null , setPending , config ) , [
1553
- setPending ,
1554
- config ,
1555
- ] ) ;
1538
+ // The ` start` method can be stored on a ref, since `setPending`
1539
+ // never changes.
1540
+ const start = startTransition . bind ( null , setPending ) ;
1541
+ mountRef ( start ) ;
1556
1542
return [ start , isPending ] ;
1557
1543
}
1558
1544
1559
- function updateTransition(
1560
- config: SuspenseConfig | void | null,
1561
- ): [(() => void ) => void , boolean ] {
1562
- const [ isPending , setPending ] = updateState ( false ) ;
1563
- const start = updateCallback ( startTransition . bind ( null , setPending , config ) , [
1564
- setPending ,
1565
- config ,
1566
- ] ) ;
1545
+ function updateTransition(): [(() => void ) => void , boolean ] {
1546
+ const [ isPending ] = updateState ( false ) ;
1547
+ const startRef = updateRef ( ) ;
1548
+ const start : ( ( ) => void ) => void = ( startRef . current : any ) ;
1567
1549
return [ start , isPending ] ;
1568
1550
}
1569
1551
1570
- function rerenderTransition(
1571
- config: SuspenseConfig | void | null,
1572
- ): [(() => void ) => void , boolean ] {
1573
- const [ isPending , setPending ] = rerenderState ( false ) ;
1574
- const start = updateCallback ( startTransition . bind ( null , setPending , config ) , [
1575
- setPending ,
1576
- config ,
1577
- ] ) ;
1552
+ function rerenderTransition(): [(() => void ) => void , boolean ] {
1553
+ const [ isPending ] = rerenderState ( false ) ;
1554
+ const startRef = updateRef ( ) ;
1555
+ const start : ( ( ) => void ) => void = ( startRef . current : any ) ;
1578
1556
return [ start , isPending ] ;
1579
1557
}
1580
1558
@@ -1986,17 +1964,15 @@ if (__DEV__) {
1986
1964
mountHookTypesDev ( ) ;
1987
1965
return mountDebugValue ( value , formatterFn ) ;
1988
1966
} ,
1989
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
1967
+ useDeferredValue< T > (value: T): T {
1990
1968
currentHookNameInDev = 'useDeferredValue' ;
1991
1969
mountHookTypesDev ( ) ;
1992
- return mountDeferredValue ( value , config ) ;
1970
+ return mountDeferredValue ( value ) ;
1993
1971
} ,
1994
- useTransition(
1995
- config: SuspenseConfig | void | null,
1996
- ): [(() => void ) => void , boolean ] {
1972
+ useTransition(): [(() => void ) => void , boolean ] {
1997
1973
currentHookNameInDev = 'useTransition' ;
1998
1974
mountHookTypesDev ( ) ;
1999
- return mountTransition ( config ) ;
1975
+ return mountTransition ( ) ;
2000
1976
} ,
2001
1977
useMutableSource< Source , Snapshot > (
2002
1978
source: MutableSource< Source > ,
@@ -2110,17 +2086,15 @@ if (__DEV__) {
2110
2086
updateHookTypesDev ( ) ;
2111
2087
return mountDebugValue ( value , formatterFn ) ;
2112
2088
} ,
2113
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2089
+ useDeferredValue< T > (value: T): T {
2114
2090
currentHookNameInDev = 'useDeferredValue' ;
2115
2091
updateHookTypesDev ( ) ;
2116
- return mountDeferredValue ( value , config ) ;
2092
+ return mountDeferredValue ( value ) ;
2117
2093
} ,
2118
- useTransition(
2119
- config: SuspenseConfig | void | null,
2120
- ): [(() => void ) => void , boolean ] {
2094
+ useTransition(): [(() => void ) => void , boolean ] {
2121
2095
currentHookNameInDev = 'useTransition' ;
2122
2096
updateHookTypesDev ( ) ;
2123
- return mountTransition ( config ) ;
2097
+ return mountTransition ( ) ;
2124
2098
} ,
2125
2099
useMutableSource< Source , Snapshot > (
2126
2100
source: MutableSource< Source > ,
@@ -2234,17 +2208,15 @@ if (__DEV__) {
2234
2208
updateHookTypesDev ( ) ;
2235
2209
return updateDebugValue ( value , formatterFn ) ;
2236
2210
} ,
2237
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2211
+ useDeferredValue< T > (value: T): T {
2238
2212
currentHookNameInDev = 'useDeferredValue' ;
2239
2213
updateHookTypesDev ( ) ;
2240
- return updateDeferredValue ( value , config ) ;
2214
+ return updateDeferredValue ( value ) ;
2241
2215
} ,
2242
- useTransition(
2243
- config: SuspenseConfig | void | null,
2244
- ): [(() => void ) => void , boolean ] {
2216
+ useTransition(): [(() => void ) => void , boolean ] {
2245
2217
currentHookNameInDev = 'useTransition' ;
2246
2218
updateHookTypesDev ( ) ;
2247
- return updateTransition ( config ) ;
2219
+ return updateTransition ( ) ;
2248
2220
} ,
2249
2221
useMutableSource< Source , Snapshot > (
2250
2222
source: MutableSource< Source > ,
@@ -2359,17 +2331,15 @@ if (__DEV__) {
2359
2331
updateHookTypesDev ( ) ;
2360
2332
return updateDebugValue ( value , formatterFn ) ;
2361
2333
} ,
2362
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2334
+ useDeferredValue< T > (value: T): T {
2363
2335
currentHookNameInDev = 'useDeferredValue' ;
2364
2336
updateHookTypesDev ( ) ;
2365
- return rerenderDeferredValue ( value , config ) ;
2337
+ return rerenderDeferredValue ( value ) ;
2366
2338
} ,
2367
- useTransition(
2368
- config: SuspenseConfig | void | null,
2369
- ): [(() => void ) => void , boolean ] {
2339
+ useTransition(): [(() => void ) => void , boolean ] {
2370
2340
currentHookNameInDev = 'useTransition' ;
2371
2341
updateHookTypesDev ( ) ;
2372
- return rerenderTransition ( config ) ;
2342
+ return rerenderTransition ( ) ;
2373
2343
} ,
2374
2344
useMutableSource< Source , Snapshot > (
2375
2345
source: MutableSource< Source > ,
@@ -2494,19 +2464,17 @@ if (__DEV__) {
2494
2464
mountHookTypesDev ( ) ;
2495
2465
return mountDebugValue ( value , formatterFn ) ;
2496
2466
} ,
2497
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2467
+ useDeferredValue< T > (value: T): T {
2498
2468
currentHookNameInDev = 'useDeferredValue' ;
2499
2469
warnInvalidHookAccess ( ) ;
2500
2470
mountHookTypesDev ( ) ;
2501
- return mountDeferredValue ( value , config ) ;
2471
+ return mountDeferredValue ( value ) ;
2502
2472
} ,
2503
- useTransition(
2504
- config: SuspenseConfig | void | null,
2505
- ): [(() => void ) => void , boolean ] {
2473
+ useTransition(): [(() => void ) => void , boolean ] {
2506
2474
currentHookNameInDev = 'useTransition' ;
2507
2475
warnInvalidHookAccess ( ) ;
2508
2476
mountHookTypesDev ( ) ;
2509
- return mountTransition ( config ) ;
2477
+ return mountTransition ( ) ;
2510
2478
} ,
2511
2479
useMutableSource< Source , Snapshot > (
2512
2480
source: MutableSource< Source > ,
@@ -2633,19 +2601,17 @@ if (__DEV__) {
2633
2601
updateHookTypesDev ( ) ;
2634
2602
return updateDebugValue ( value , formatterFn ) ;
2635
2603
} ,
2636
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2604
+ useDeferredValue< T > (value: T): T {
2637
2605
currentHookNameInDev = 'useDeferredValue' ;
2638
2606
warnInvalidHookAccess ( ) ;
2639
2607
updateHookTypesDev ( ) ;
2640
- return updateDeferredValue ( value , config ) ;
2608
+ return updateDeferredValue ( value ) ;
2641
2609
} ,
2642
- useTransition(
2643
- config: SuspenseConfig | void | null,
2644
- ): [(() => void ) => void , boolean ] {
2610
+ useTransition(): [(() => void ) => void , boolean ] {
2645
2611
currentHookNameInDev = 'useTransition' ;
2646
2612
warnInvalidHookAccess ( ) ;
2647
2613
updateHookTypesDev ( ) ;
2648
- return updateTransition ( config ) ;
2614
+ return updateTransition ( ) ;
2649
2615
} ,
2650
2616
useMutableSource< Source , Snapshot > (
2651
2617
source: MutableSource< Source > ,
@@ -2773,19 +2739,17 @@ if (__DEV__) {
2773
2739
updateHookTypesDev ( ) ;
2774
2740
return updateDebugValue ( value , formatterFn ) ;
2775
2741
} ,
2776
- useDeferredValue< T > (value: T, config: TimeoutConfig | void | null ): T {
2742
+ useDeferredValue< T > (value: T): T {
2777
2743
currentHookNameInDev = 'useDeferredValue' ;
2778
2744
warnInvalidHookAccess ( ) ;
2779
2745
updateHookTypesDev ( ) ;
2780
- return rerenderDeferredValue ( value , config ) ;
2746
+ return rerenderDeferredValue ( value ) ;
2781
2747
} ,
2782
- useTransition(
2783
- config: SuspenseConfig | void | null,
2784
- ): [(() => void ) => void , boolean ] {
2748
+ useTransition(): [(() => void ) => void , boolean ] {
2785
2749
currentHookNameInDev = 'useTransition' ;
2786
2750
warnInvalidHookAccess ( ) ;
2787
2751
updateHookTypesDev ( ) ;
2788
- return rerenderTransition ( config ) ;
2752
+ return rerenderTransition ( ) ;
2789
2753
} ,
2790
2754
useMutableSource< Source , Snapshot > (
2791
2755
source: MutableSource< Source > ,
0 commit comments