@samitouri / QOS-React-2 / commits / ddd1faa197

Remove config argument from useTransition (#19719)

And `useDeferredValue`. The options were already disabled in previous commits, so this doesn't change any behavior. I upated type signatures and cleaned up the hook implementation a bit — no longer have to wrap the `start` method with `useCallback`, because its only remaining dependency is a `setState` method, which never changes. Instead, we can store the `start` method on a ref.

Andrew Clark committed Aug 28, 2020 at 13:49 UTC ddd1faa1972b614dfbfae205f2aa4a6c0b39a759
10 files changed +118 -223
packages/react-debug-tools/src/ReactDebugHooks.js
+3 -10
@@ -20,7 +20,6 @@ import type {
20 } from 'react-reconciler/src/ReactInternalTypes';
21 import type {OpaqueIDType} from 'react-reconciler/src/ReactFiberHostConfig';
22
23 -import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberTransition';
23 import {NoMode} from 'react-reconciler/src/ReactTypeOfMode';
24
25 import ErrorStackParser from 'error-stack-parser';
@@ -62,10 +61,6 @@ type Hook = {
61 next: Hook | null,
62 };
63
65 -type TimeoutConfig = {|
66 - timeoutMs: number,
67 -|};
68 -
64 function getPrimitiveStackCache(): Map<string, Array<any>> {
65 // This initializes a cache of all primitive hooks so that the top
66 // most stack frames added by calling the primitive hook can be removed.
@@ -258,9 +253,7 @@ function useMutableSource<Source, Snapshot>(
253 return value;
254 }
255
261 -function useTransition(
262 - config: SuspenseConfig | null | void,
263 -): [(() => void) => void, boolean] {
256 +function useTransition(): [(() => void) => void, boolean] {
257 // useTransition() composes multiple hooks internally.
258 // Advance the current hook index the same number of times
259 // so that subsequent hooks have the right memoized state.
@@ -269,12 +262,12 @@ function useTransition(
262 hookLog.push({
263 primitive: 'Transition',
264 stackError: new Error(),
272 - value: config,
265 + value: undefined,
266 });
267 return [callback => {}, false];
268 }
269
277 -function useDeferredValue<T>(value: T, config: TimeoutConfig | null | void): T {
270 +function useDeferredValue<T>(value: T): T {
271 // useDeferredValue() composes multiple hooks internally.
272 // Advance the current hook index the same number of times
273 // so that subsequent hooks have the right memoized state.
packages/react-dom/src/server/ReactPartialRendererHooks.js
+2 -9
@@ -15,7 +15,6 @@ import type {
15 MutableSourceSubscribeFn,
16 ReactContext,
17 } from 'shared/ReactTypes';
18 -import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberTransition';
18 import type PartialRenderer from './ReactPartialRenderer';
19
20 import {validateContextBounds} from './ReactPartialRendererContext';
@@ -42,10 +41,6 @@ type Hook = {|
41 next: Hook | null,
42 |};
43
45 -type TimeoutConfig = {|
46 - timeoutMs: number,
47 -|};
48 -
44 type OpaqueIDType = string;
45
46 let currentlyRenderingComponent: Object | null = null;
@@ -468,14 +463,12 @@ function useMutableSource<Source, Snapshot>(
463 return getSnapshot(source._source);
464 }
465
471 -function useDeferredValue<T>(value: T, config: TimeoutConfig | null | void): T {
466 +function useDeferredValue<T>(value: T): T {
467 resolveCurrentlyRenderingComponent();
468 return value;
469 }
470
476 -function useTransition(
477 - config: SuspenseConfig | null | void,
478 -): [(callback: () => void) => void, boolean] {
471 +function useTransition(): [(callback: () => void) => void, boolean] {
472 resolveCurrentlyRenderingComponent();
473 const startTransition = callback => {
474 callback();
packages/react-reconciler/src/ReactFiberHooks.new.js
+51 -87
@@ -16,7 +16,6 @@ import type {
16 import type {Fiber, Dispatcher} from './ReactInternalTypes';
17 import type {Lanes, Lane} from './ReactFiberLane';
18 import type {HookEffectTag} from './ReactHookEffectTags';
19 -import type {SuspenseConfig} from './ReactFiberTransition';
19 import type {ReactPriorityLevel} from './ReactInternalTypes';
20 import type {FiberRoot} from './ReactInternalTypes';
21 import type {OpaqueIDType} from './ReactFiberHostConfig';
@@ -151,10 +150,6 @@ export type Effect = {|
150
151 export type FunctionComponentUpdateQueue = {|lastEffect: Effect | null|};
152
154 -type TimeoutConfig = {|
155 - timeoutMs: number,
156 -|};
157 -
153 type BasicStateAction<S> = (S => S) | S;
154
155 type Dispatch<A> = A => void;
@@ -1432,10 +1427,7 @@ function updateMemo<T>(
1427 return nextValue;
1428 }
1429
1435 -function mountDeferredValue<T>(
1436 - value: T,
1437 - config: TimeoutConfig | void | null,
1438 -): T {
1430 +function mountDeferredValue<T>(value: T): T {
1431 const [prevValue, setValue] = mountState(value);
1432 mountEffect(() => {
1433 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1445,14 +1437,11 @@ function mountDeferredValue<T>(
1437 } finally {
1438 ReactCurrentBatchConfig.transition = prevTransition;
1439 }
1448 - }, [value, config]);
1440 + }, [value]);
1441 return prevValue;
1442 }
1443
1452 -function updateDeferredValue<T>(
1453 - value: T,
1454 - config: TimeoutConfig | void | null,
1455 -): T {
1444 +function updateDeferredValue<T>(value: T): T {
1445 const [prevValue, setValue] = updateState(value);
1446 updateEffect(() => {
1447 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1462,14 +1451,11 @@ function updateDeferredValue<T>(
1451 } finally {
1452 ReactCurrentBatchConfig.transition = prevTransition;
1453 }
1465 - }, [value, config]);
1454 + }, [value]);
1455 return prevValue;
1456 }
1457
1469 -function rerenderDeferredValue<T>(
1470 - value: T,
1471 - config: TimeoutConfig | void | null,
1472 -): T {
1458 +function rerenderDeferredValue<T>(value: T): T {
1459 const [prevValue, setValue] = rerenderState(value);
1460 updateEffect(() => {
1461 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1479,11 +1465,11 @@ function rerenderDeferredValue<T>(
1465 } finally {
1466 ReactCurrentBatchConfig.transition = prevTransition;
1467 }
1482 - }, [value, config]);
1468 + }, [value]);
1469 return prevValue;
1470 }
1471
1486 -function startTransition(setPending, config, callback) {
1472 +function startTransition(setPending, callback) {
1473 const priorityLevel = getCurrentPriorityLevel();
1474 if (decoupleUpdatePriorityFromScheduler) {
1475 const previousLanePriority = getCurrentUpdateLanePriority();
@@ -1500,7 +1486,9 @@ function startTransition(setPending, config, callback) {
1486 },
1487 );
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.
1492 setCurrentUpdateLanePriority(DefaultLanePriority);
1493
1494 runWithPriority(
@@ -1545,36 +1533,26 @@ function startTransition(setPending, config, callback) {
1533 }
1534 }
1535
1548 -function mountTransition(
1549 - config: SuspenseConfig | void | null,
1550 -): [(() => void) => void, boolean] {
1536 +function mountTransition(): [(() => void) => void, boolean] {
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);
1542 return [start, isPending];
1543 }
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);
1549 return [start, isPending];
1550 }
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);
1556 return [start, isPending];
1557 }
1558
@@ -1986,17 +1964,15 @@ if (__DEV__) {
1964 mountHookTypesDev();
1965 return mountDebugValue(value, formatterFn);
1966 },
1989 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
1967 + useDeferredValue<T>(value: T): T {
1968 currentHookNameInDev = 'useDeferredValue';
1969 mountHookTypesDev();
1992 - return mountDeferredValue(value, config);
1970 + return mountDeferredValue(value);
1971 },
1994 - useTransition(
1995 - config: SuspenseConfig | void | null,
1996 - ): [(() => void) => void, boolean] {
1972 + useTransition(): [(() => void) => void, boolean] {
1973 currentHookNameInDev = 'useTransition';
1974 mountHookTypesDev();
1999 - return mountTransition(config);
1975 + return mountTransition();
1976 },
1977 useMutableSource<Source, Snapshot>(
1978 source: MutableSource<Source>,
@@ -2110,17 +2086,15 @@ if (__DEV__) {
2086 updateHookTypesDev();
2087 return mountDebugValue(value, formatterFn);
2088 },
2113 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2089 + useDeferredValue<T>(value: T): T {
2090 currentHookNameInDev = 'useDeferredValue';
2091 updateHookTypesDev();
2116 - return mountDeferredValue(value, config);
2092 + return mountDeferredValue(value);
2093 },
2118 - useTransition(
2119 - config: SuspenseConfig | void | null,
2120 - ): [(() => void) => void, boolean] {
2094 + useTransition(): [(() => void) => void, boolean] {
2095 currentHookNameInDev = 'useTransition';
2096 updateHookTypesDev();
2123 - return mountTransition(config);
2097 + return mountTransition();
2098 },
2099 useMutableSource<Source, Snapshot>(
2100 source: MutableSource<Source>,
@@ -2234,17 +2208,15 @@ if (__DEV__) {
2208 updateHookTypesDev();
2209 return updateDebugValue(value, formatterFn);
2210 },
2237 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2211 + useDeferredValue<T>(value: T): T {
2212 currentHookNameInDev = 'useDeferredValue';
2213 updateHookTypesDev();
2240 - return updateDeferredValue(value, config);
2214 + return updateDeferredValue(value);
2215 },
2242 - useTransition(
2243 - config: SuspenseConfig | void | null,
2244 - ): [(() => void) => void, boolean] {
2216 + useTransition(): [(() => void) => void, boolean] {
2217 currentHookNameInDev = 'useTransition';
2218 updateHookTypesDev();
2247 - return updateTransition(config);
2219 + return updateTransition();
2220 },
2221 useMutableSource<Source, Snapshot>(
2222 source: MutableSource<Source>,
@@ -2359,17 +2331,15 @@ if (__DEV__) {
2331 updateHookTypesDev();
2332 return updateDebugValue(value, formatterFn);
2333 },
2362 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2334 + useDeferredValue<T>(value: T): T {
2335 currentHookNameInDev = 'useDeferredValue';
2336 updateHookTypesDev();
2365 - return rerenderDeferredValue(value, config);
2337 + return rerenderDeferredValue(value);
2338 },
2367 - useTransition(
2368 - config: SuspenseConfig | void | null,
2369 - ): [(() => void) => void, boolean] {
2339 + useTransition(): [(() => void) => void, boolean] {
2340 currentHookNameInDev = 'useTransition';
2341 updateHookTypesDev();
2372 - return rerenderTransition(config);
2342 + return rerenderTransition();
2343 },
2344 useMutableSource<Source, Snapshot>(
2345 source: MutableSource<Source>,
@@ -2494,19 +2464,17 @@ if (__DEV__) {
2464 mountHookTypesDev();
2465 return mountDebugValue(value, formatterFn);
2466 },
2497 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2467 + useDeferredValue<T>(value: T): T {
2468 currentHookNameInDev = 'useDeferredValue';
2469 warnInvalidHookAccess();
2470 mountHookTypesDev();
2501 - return mountDeferredValue(value, config);
2471 + return mountDeferredValue(value);
2472 },
2503 - useTransition(
2504 - config: SuspenseConfig | void | null,
2505 - ): [(() => void) => void, boolean] {
2473 + useTransition(): [(() => void) => void, boolean] {
2474 currentHookNameInDev = 'useTransition';
2475 warnInvalidHookAccess();
2476 mountHookTypesDev();
2509 - return mountTransition(config);
2477 + return mountTransition();
2478 },
2479 useMutableSource<Source, Snapshot>(
2480 source: MutableSource<Source>,
@@ -2633,19 +2601,17 @@ if (__DEV__) {
2601 updateHookTypesDev();
2602 return updateDebugValue(value, formatterFn);
2603 },
2636 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2604 + useDeferredValue<T>(value: T): T {
2605 currentHookNameInDev = 'useDeferredValue';
2606 warnInvalidHookAccess();
2607 updateHookTypesDev();
2640 - return updateDeferredValue(value, config);
2608 + return updateDeferredValue(value);
2609 },
2642 - useTransition(
2643 - config: SuspenseConfig | void | null,
2644 - ): [(() => void) => void, boolean] {
2610 + useTransition(): [(() => void) => void, boolean] {
2611 currentHookNameInDev = 'useTransition';
2612 warnInvalidHookAccess();
2613 updateHookTypesDev();
2648 - return updateTransition(config);
2614 + return updateTransition();
2615 },
2616 useMutableSource<Source, Snapshot>(
2617 source: MutableSource<Source>,
@@ -2773,19 +2739,17 @@ if (__DEV__) {
2739 updateHookTypesDev();
2740 return updateDebugValue(value, formatterFn);
2741 },
2776 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2742 + useDeferredValue<T>(value: T): T {
2743 currentHookNameInDev = 'useDeferredValue';
2744 warnInvalidHookAccess();
2745 updateHookTypesDev();
2780 - return rerenderDeferredValue(value, config);
2746 + return rerenderDeferredValue(value);
2747 },
2782 - useTransition(
2783 - config: SuspenseConfig | void | null,
2784 - ): [(() => void) => void, boolean] {
2748 + useTransition(): [(() => void) => void, boolean] {
2749 currentHookNameInDev = 'useTransition';
2750 warnInvalidHookAccess();
2751 updateHookTypesDev();
2788 - return rerenderTransition(config);
2752 + return rerenderTransition();
2753 },
2754 useMutableSource<Source, Snapshot>(
2755 source: MutableSource<Source>,
packages/react-reconciler/src/ReactFiberHooks.old.js
+51 -87
@@ -16,7 +16,6 @@ import type {
16 import type {Fiber, Dispatcher} from './ReactInternalTypes';
17 import type {Lanes, Lane} from './ReactFiberLane';
18 import type {HookEffectTag} from './ReactHookEffectTags';
19 -import type {SuspenseConfig} from './ReactFiberTransition';
19 import type {ReactPriorityLevel} from './ReactInternalTypes';
20 import type {FiberRoot} from './ReactInternalTypes';
21 import type {OpaqueIDType} from './ReactFiberHostConfig';
@@ -150,10 +149,6 @@ export type Effect = {|
149
150 export type FunctionComponentUpdateQueue = {|lastEffect: Effect | null|};
151
153 -type TimeoutConfig = {|
154 - timeoutMs: number,
155 -|};
156 -
152 type BasicStateAction<S> = (S => S) | S;
153
154 type Dispatch<A> = A => void;
@@ -1431,10 +1426,7 @@ function updateMemo<T>(
1426 return nextValue;
1427 }
1428
1434 -function mountDeferredValue<T>(
1435 - value: T,
1436 - config: TimeoutConfig | void | null,
1437 -): T {
1429 +function mountDeferredValue<T>(value: T): T {
1430 const [prevValue, setValue] = mountState(value);
1431 mountEffect(() => {
1432 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1444,14 +1436,11 @@ function mountDeferredValue<T>(
1436 } finally {
1437 ReactCurrentBatchConfig.transition = prevTransition;
1438 }
1447 - }, [value, config]);
1439 + }, [value]);
1440 return prevValue;
1441 }
1442
1451 -function updateDeferredValue<T>(
1452 - value: T,
1453 - config: TimeoutConfig | void | null,
1454 -): T {
1443 +function updateDeferredValue<T>(value: T): T {
1444 const [prevValue, setValue] = updateState(value);
1445 updateEffect(() => {
1446 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1461,14 +1450,11 @@ function updateDeferredValue<T>(
1450 } finally {
1451 ReactCurrentBatchConfig.transition = prevTransition;
1452 }
1464 - }, [value, config]);
1453 + }, [value]);
1454 return prevValue;
1455 }
1456
1468 -function rerenderDeferredValue<T>(
1469 - value: T,
1470 - config: TimeoutConfig | void | null,
1471 -): T {
1457 +function rerenderDeferredValue<T>(value: T): T {
1458 const [prevValue, setValue] = rerenderState(value);
1459 updateEffect(() => {
1460 const prevTransition = ReactCurrentBatchConfig.transition;
@@ -1478,11 +1464,11 @@ function rerenderDeferredValue<T>(
1464 } finally {
1465 ReactCurrentBatchConfig.transition = prevTransition;
1466 }
1481 - }, [value, config]);
1467 + }, [value]);
1468 return prevValue;
1469 }
1470
1485 -function startTransition(setPending, config, callback) {
1471 +function startTransition(setPending, callback) {
1472 const priorityLevel = getCurrentPriorityLevel();
1473 if (decoupleUpdatePriorityFromScheduler) {
1474 const previousLanePriority = getCurrentUpdateLanePriority();
@@ -1499,7 +1485,9 @@ function startTransition(setPending, config, callback) {
1485 },
1486 );
1487
1502 - // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1488 + // TODO: Can remove this. Was only necessary because we used to give
1489 + // different behavior to transitions without a config object. Now they are
1490 + // all treated the same.
1491 setCurrentUpdateLanePriority(DefaultLanePriority);
1492
1493 runWithPriority(
@@ -1544,36 +1532,26 @@ function startTransition(setPending, config, callback) {
1532 }
1533 }
1534
1547 -function mountTransition(
1548 - config: SuspenseConfig | void | null,
1549 -): [(() => void) => void, boolean] {
1535 +function mountTransition(): [(() => void) => void, boolean] {
1536 const [isPending, setPending] = mountState(false);
1551 - const start = mountCallback(startTransition.bind(null, setPending, config), [
1552 - setPending,
1553 - config,
1554 - ]);
1537 + // The `start` method can be stored on a ref, since `setPending`
1538 + // never changes.
1539 + const start = startTransition.bind(null, setPending);
1540 + mountRef(start);
1541 return [start, isPending];
1542 }
1543
1558 -function updateTransition(
1559 - config: SuspenseConfig | void | null,
1560 -): [(() => void) => void, boolean] {
1561 - const [isPending, setPending] = updateState(false);
1562 - const start = updateCallback(startTransition.bind(null, setPending, config), [
1563 - setPending,
1564 - config,
1565 - ]);
1544 +function updateTransition(): [(() => void) => void, boolean] {
1545 + const [isPending] = updateState(false);
1546 + const startRef = updateRef();
1547 + const start: (() => void) => void = (startRef.current: any);
1548 return [start, isPending];
1549 }
1550
1569 -function rerenderTransition(
1570 - config: SuspenseConfig | void | null,
1571 -): [(() => void) => void, boolean] {
1572 - const [isPending, setPending] = rerenderState(false);
1573 - const start = updateCallback(startTransition.bind(null, setPending, config), [
1574 - setPending,
1575 - config,
1576 - ]);
1551 +function rerenderTransition(): [(() => void) => void, boolean] {
1552 + const [isPending] = rerenderState(false);
1553 + const startRef = updateRef();
1554 + const start: (() => void) => void = (startRef.current: any);
1555 return [start, isPending];
1556 }
1557
@@ -1984,17 +1962,15 @@ if (__DEV__) {
1962 mountHookTypesDev();
1963 return mountDebugValue(value, formatterFn);
1964 },
1987 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
1965 + useDeferredValue<T>(value: T): T {
1966 currentHookNameInDev = 'useDeferredValue';
1967 mountHookTypesDev();
1990 - return mountDeferredValue(value, config);
1968 + return mountDeferredValue(value);
1969 },
1992 - useTransition(
1993 - config: SuspenseConfig | void | null,
1994 - ): [(() => void) => void, boolean] {
1970 + useTransition(): [(() => void) => void, boolean] {
1971 currentHookNameInDev = 'useTransition';
1972 mountHookTypesDev();
1997 - return mountTransition(config);
1973 + return mountTransition();
1974 },
1975 useMutableSource<Source, Snapshot>(
1976 source: MutableSource<Source>,
@@ -2108,17 +2084,15 @@ if (__DEV__) {
2084 updateHookTypesDev();
2085 return mountDebugValue(value, formatterFn);
2086 },
2111 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2087 + useDeferredValue<T>(value: T): T {
2088 currentHookNameInDev = 'useDeferredValue';
2089 updateHookTypesDev();
2114 - return mountDeferredValue(value, config);
2090 + return mountDeferredValue(value);
2091 },
2116 - useTransition(
2117 - config: SuspenseConfig | void | null,
2118 - ): [(() => void) => void, boolean] {
2092 + useTransition(): [(() => void) => void, boolean] {
2093 currentHookNameInDev = 'useTransition';
2094 updateHookTypesDev();
2121 - return mountTransition(config);
2095 + return mountTransition();
2096 },
2097 useMutableSource<Source, Snapshot>(
2098 source: MutableSource<Source>,
@@ -2232,17 +2206,15 @@ if (__DEV__) {
2206 updateHookTypesDev();
2207 return updateDebugValue(value, formatterFn);
2208 },
2235 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2209 + useDeferredValue<T>(value: T): T {
2210 currentHookNameInDev = 'useDeferredValue';
2211 updateHookTypesDev();
2238 - return updateDeferredValue(value, config);
2212 + return updateDeferredValue(value);
2213 },
2240 - useTransition(
2241 - config: SuspenseConfig | void | null,
2242 - ): [(() => void) => void, boolean] {
2214 + useTransition(): [(() => void) => void, boolean] {
2215 currentHookNameInDev = 'useTransition';
2216 updateHookTypesDev();
2245 - return updateTransition(config);
2217 + return updateTransition();
2218 },
2219 useMutableSource<Source, Snapshot>(
2220 source: MutableSource<Source>,
@@ -2357,17 +2329,15 @@ if (__DEV__) {
2329 updateHookTypesDev();
2330 return updateDebugValue(value, formatterFn);
2331 },
2360 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2332 + useDeferredValue<T>(value: T): T {
2333 currentHookNameInDev = 'useDeferredValue';
2334 updateHookTypesDev();
2363 - return rerenderDeferredValue(value, config);
2335 + return rerenderDeferredValue(value);
2336 },
2365 - useTransition(
2366 - config: SuspenseConfig | void | null,
2367 - ): [(() => void) => void, boolean] {
2337 + useTransition(): [(() => void) => void, boolean] {
2338 currentHookNameInDev = 'useTransition';
2339 updateHookTypesDev();
2370 - return rerenderTransition(config);
2340 + return rerenderTransition();
2341 },
2342 useMutableSource<Source, Snapshot>(
2343 source: MutableSource<Source>,
@@ -2492,19 +2462,17 @@ if (__DEV__) {
2462 mountHookTypesDev();
2463 return mountDebugValue(value, formatterFn);
2464 },
2495 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2465 + useDeferredValue<T>(value: T): T {
2466 currentHookNameInDev = 'useDeferredValue';
2467 warnInvalidHookAccess();
2468 mountHookTypesDev();
2499 - return mountDeferredValue(value, config);
2469 + return mountDeferredValue(value);
2470 },
2501 - useTransition(
2502 - config: SuspenseConfig | void | null,
2503 - ): [(() => void) => void, boolean] {
2471 + useTransition(): [(() => void) => void, boolean] {
2472 currentHookNameInDev = 'useTransition';
2473 warnInvalidHookAccess();
2474 mountHookTypesDev();
2507 - return mountTransition(config);
2475 + return mountTransition();
2476 },
2477 useMutableSource<Source, Snapshot>(
2478 source: MutableSource<Source>,
@@ -2631,19 +2599,17 @@ if (__DEV__) {
2599 updateHookTypesDev();
2600 return updateDebugValue(value, formatterFn);
2601 },
2634 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2602 + useDeferredValue<T>(value: T): T {
2603 currentHookNameInDev = 'useDeferredValue';
2604 warnInvalidHookAccess();
2605 updateHookTypesDev();
2638 - return updateDeferredValue(value, config);
2606 + return updateDeferredValue(value);
2607 },
2640 - useTransition(
2641 - config: SuspenseConfig | void | null,
2642 - ): [(() => void) => void, boolean] {
2608 + useTransition(): [(() => void) => void, boolean] {
2609 currentHookNameInDev = 'useTransition';
2610 warnInvalidHookAccess();
2611 updateHookTypesDev();
2646 - return updateTransition(config);
2612 + return updateTransition();
2613 },
2614 useMutableSource<Source, Snapshot>(
2615 source: MutableSource<Source>,
@@ -2771,19 +2737,17 @@ if (__DEV__) {
2737 updateHookTypesDev();
2738 return updateDebugValue(value, formatterFn);
2739 },
2774 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T {
2740 + useDeferredValue<T>(value: T): T {
2741 currentHookNameInDev = 'useDeferredValue';
2742 warnInvalidHookAccess();
2743 updateHookTypesDev();
2778 - return rerenderDeferredValue(value, config);
2744 + return rerenderDeferredValue(value);
2745 },
2780 - useTransition(
2781 - config: SuspenseConfig | void | null,
2782 - ): [(() => void) => void, boolean] {
2746 + useTransition(): [(() => void) => void, boolean] {
2747 currentHookNameInDev = 'useTransition';
2748 warnInvalidHookAccess();
2749 updateHookTypesDev();
2786 - return rerenderTransition(config);
2750 + return rerenderTransition();
2751 },
2752 useMutableSource<Source, Snapshot>(
2753 source: MutableSource<Source>,
packages/react-reconciler/src/ReactFiberThrow.new.js
+2 -2
@@ -314,8 +314,8 @@ function throwException(
314 // that we can show the initial loading state as quickly as possible.
315 //
316 // If we hit a "Delayed" case, such as when we'd switch from content back into
317 - // a fallback, then we should always suspend/restart. SuspenseConfig applies to
318 - // this case. If none is defined, JND is used instead.
317 + // a fallback, then we should always suspend/restart. Transitions apply
318 + // to this case. If none is defined, JND is used instead.
319 //
320 // If we're already showing a fallback and it gets "retried", allowing us to show
321 // another level, but there's still an inner boundary that would show a fallback,
packages/react-reconciler/src/ReactFiberThrow.old.js
+2 -2
@@ -316,8 +316,8 @@ function throwException(
316 // that we can show the initial loading state as quickly as possible.
317 //
318 // If we hit a "Delayed" case, such as when we'd switch from content back into
319 - // a fallback, then we should always suspend/restart. SuspenseConfig applies to
320 - // this case. If none is defined, JND is used instead.
319 + // a fallback, then we should always suspend/restart. Transitions apply
320 + // to this case. If none is defined, JND is used instead.
321 //
322 // If we're already showing a fallback and it gets "retried", allowing us to show
323 // another level, but there's still an inner boundary that would show a fallback,
packages/react-reconciler/src/ReactFiberTransition.js
-12
@@ -9,18 +9,6 @@
9
10 import ReactSharedInternals from 'shared/ReactSharedInternals';
11
12 -// Deprecated
13 -export type SuspenseConfig = {|
14 - timeoutMs: number,
15 - busyDelayMs?: number,
16 - busyMinDurationMs?: number,
17 -|};
18 -
19 -// Deprecated
20 -export type TimeoutConfig = {|
21 - timeoutMs: number,
22 -|};
23 -
12 const {ReactCurrentBatchConfig} = ReactSharedInternals;
13
14 export const NoTransition = 0;
packages/react-reconciler/src/ReactInternalTypes.js
+2 -5
@@ -27,7 +27,6 @@ import type {RootTag} from './ReactRootTags';
27 import type {TimeoutHandle, NoTimeout} from './ReactFiberHostConfig';
28 import type {Wakeable} from 'shared/ReactTypes';
29 import type {Interaction} from 'scheduler/src/Tracing';
30 -import type {SuspenseConfig, TimeoutConfig} from './ReactFiberTransition';
30
31 export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90;
32
@@ -291,10 +290,8 @@ export type Dispatcher = {|
290 deps: Array<mixed> | void | null,
291 ): void,
292 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void,
294 - useDeferredValue<T>(value: T, config: TimeoutConfig | void | null): T,
295 - useTransition(
296 - config: SuspenseConfig | void | null,
297 - ): [(() => void) => void, boolean],
293 + useDeferredValue<T>(value: T): T,
294 + useTransition(): [(() => void) => void, boolean],
295 useMutableSource<Source, Snapshot>(
296 source: MutableSource<Source>,
297 getSnapshot: MutableSourceGetSnapshotFn<Source, Snapshot>,
packages/react/src/ReactBatchConfig.js
+1 -3
@@ -7,15 +7,13 @@
7 * @flow
8 */
9
10 -import type {SuspenseConfig} from 'react-reconciler/src/ReactFiberTransition';
11 -
10 import ReactCurrentBatchConfig from './ReactCurrentBatchConfig';
11
12 // This is a copy of startTransition, except if null or undefined is passed,
13 // then updates inside the scope are opted-out of the outer transition scope.
14 // TODO: Deprecated. Remove in favor of startTransition. Figure out how scopes
15 // should nest, and whether we need an API to opt-out nested scopes.
18 -export function withSuspenseConfig(scope: () => void, config?: SuspenseConfig) {
16 +export function withSuspenseConfig(scope: () => void, config?: mixed) {
17 const prevTransition = ReactCurrentBatchConfig.transition;
18 ReactCurrentBatchConfig.transition =
19 config === undefined || config === null ? 0 : 1;
packages/react/src/ReactHooks.js
+4 -6
@@ -151,16 +151,14 @@ export function useDebugValue<T>(
151
152 export const emptyObject = {};
153
154 -export function useTransition(
155 - config: ?Object,
156 -): [(() => void) => void, boolean] {
154 +export function useTransition(): [(() => void) => void, boolean] {
155 const dispatcher = resolveDispatcher();
158 - return dispatcher.useTransition(config);
156 + return dispatcher.useTransition();
157 }
158
161 -export function useDeferredValue<T>(value: T, config: ?Object): T {
159 +export function useDeferredValue<T>(value: T): T {
160 const dispatcher = resolveDispatcher();
163 - return dispatcher.useDeferredValue(value, config);
161 + return dispatcher.useDeferredValue(value);
162 }
163
164 export function useOpaqueIdentifier(): OpaqueIDType | void {