@@ -27,7 +27,9 @@ import type {
27
27
import type { Lanes , Lane } from './ReactFiberLane' ;
28
28
import type { HookFlags } from './ReactHookEffectTags' ;
29
29
import type { Flags } from './ReactFiberFlags' ;
30
+ import type { TransitionStatus } from './ReactFiberConfig' ;
30
31
32
+ import { NotPendingTransition as NoPendingHostTransition } from './ReactFiberConfig' ;
31
33
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
32
34
import {
33
35
enableDebugTracing ,
@@ -757,9 +759,9 @@ export function renderTransitionAwareHostComponentWithHooks(
757
759
current : Fiber | null ,
758
760
workInProgress : Fiber ,
759
761
lanes : Lanes ,
760
- ) : boolean {
762
+ ) : TransitionStatus {
761
763
if ( ! ( enableFormActions && enableAsyncActions ) ) {
762
- return false ;
764
+ throw new Error ( 'Not implemented.' ) ;
763
765
}
764
766
return renderWithHooks (
765
767
current ,
@@ -771,16 +773,19 @@ export function renderTransitionAwareHostComponentWithHooks(
771
773
) ;
772
774
}
773
775
774
- export function TransitionAwareHostComponent ( ) : boolean {
776
+ export function TransitionAwareHostComponent ( ) : TransitionStatus {
775
777
if ( ! ( enableFormActions && enableAsyncActions ) ) {
776
- return false ;
778
+ throw new Error ( 'Not implemented.' ) ;
777
779
}
778
780
const dispatcher = ReactCurrentDispatcher . current ;
779
- const [ booleanOrThenable ] = dispatcher . useState ( ) ;
780
- return typeof booleanOrThenable === 'boolean'
781
- ? booleanOrThenable
782
- : // This will suspend until the async action scope has finished.
783
- useThenable ( booleanOrThenable ) ;
781
+ const [ maybeThenable ] = dispatcher . useState ( ) ;
782
+ if ( typeof maybeThenable . then === 'function' ) {
783
+ const thenable : Thenable < TransitionStatus > = ( maybeThenable : any ) ;
784
+ return useThenable ( thenable ) ;
785
+ } else {
786
+ const status : TransitionStatus = maybeThenable ;
787
+ return status ;
788
+ }
784
789
}
785
790
786
791
export function checkDidRenderIdHook ( ) : boolean {
@@ -2520,6 +2525,7 @@ function startTransition<S>(
2520
2525
2521
2526
export function startHostTransition < F > (
2522
2527
formFiber: Fiber,
2528
+ pendingState: TransitionStatus,
2523
2529
callback: F => mixed ,
2524
2530
formData : F ,
2525
2531
) : void {
@@ -2551,24 +2557,24 @@ export function startHostTransition<F>(
2551
2557
// Create the state hook used by TransitionAwareHostComponent. This is
2552
2558
// essentially an inlined version of mountState.
2553
2559
const queue : UpdateQueue <
2554
- Thenable < boolean > | boolean ,
2555
- Thenable < boolean > | boolean ,
2560
+ Thenable < TransitionStatus > | TransitionStatus ,
2561
+ Thenable < TransitionStatus > | TransitionStatus ,
2556
2562
> = {
2557
2563
pending : null ,
2558
2564
lanes : NoLanes ,
2559
2565
dispatch : null ,
2560
2566
lastRenderedReducer : basicStateReducer ,
2561
- lastRenderedState : false ,
2567
+ lastRenderedState : NoPendingHostTransition ,
2562
2568
} ;
2563
2569
const stateHook : Hook = {
2564
- memoizedState : false ,
2565
- baseState : false ,
2570
+ memoizedState : NoPendingHostTransition ,
2571
+ baseState : NoPendingHostTransition ,
2566
2572
baseQueue : null ,
2567
2573
queue : queue ,
2568
2574
next : null ,
2569
2575
} ;
2570
2576
2571
- const dispatch : ( Thenable < boolean > | boolean ) = > void =
2577
+ const dispatch : ( Thenable < TransitionStatus > | TransitionStatus ) = > void =
2572
2578
( dispatchSetState . bind ( null , formFiber , queue ) : any ) ;
2573
2579
setPending = queue . dispatch = dispatch ;
2574
2580
@@ -2582,14 +2588,14 @@ export function startHostTransition<F>(
2582
2588
} else {
2583
2589
// This fiber was already upgraded to be stateful.
2584
2590
const stateHook : Hook = formFiber . memoizedState ;
2585
- const dispatch : ( Thenable < boolean > | boolean ) = > void =
2591
+ const dispatch : ( Thenable < TransitionStatus > | TransitionStatus ) = > void =
2586
2592
stateHook . queue . dispatch ;
2587
2593
setPending = dispatch ;
2588
2594
}
2589
2595
2590
2596
startTransition(
2591
- true ,
2592
- false ,
2597
+ pendingState ,
2598
+ NoPendingHostTransition ,
2593
2599
setPending,
2594
2600
// TODO: We can avoid this extra wrapper, somehow. Figure out layering
2595
2601
// once more of this function is implemented.
0 commit comments