@@ -55,6 +55,76 @@ describe('public client loading contracts', () => {
5555 } )
5656 } )
5757
58+ test ( 'a successor retains committed UI until its pending context is ready' , async ( ) => {
59+ const initialPublished = createControlledPromise < void > ( )
60+ const initialRenderAck = createControlledPromise < boolean > ( )
61+ const successorStarted = createControlledPromise < void > ( )
62+ const successorLoader = createControlledPromise < string > ( )
63+ const rootRoute = new BaseRootRoute ( { } )
64+ const initialRoute = new BaseRoute ( {
65+ getParentRoute : ( ) => rootRoute ,
66+ path : '/' ,
67+ } )
68+ const successorRoute = new BaseRoute ( {
69+ getParentRoute : ( ) => rootRoute ,
70+ path : '/successor' ,
71+ context : ( ) => ( { destinationContext : 'ready' } ) ,
72+ pendingMs : 0 ,
73+ pendingMinMs : 0 ,
74+ pendingComponent : ( ) => null ,
75+ loader : ( ) => {
76+ successorStarted . resolve ( )
77+ return successorLoader
78+ } ,
79+ } )
80+ const router = createTestRouter ( {
81+ routeTree : rootRoute . addChildren ( [ initialRoute , successorRoute ] ) ,
82+ history : createMemoryHistory ( { initialEntries : [ '/' ] } ) ,
83+ } )
84+ const startTransition = router . startTransition
85+ let waitForInitialRender = true
86+ router . startTransition = ( fn , expected ) => {
87+ fn ( )
88+ if (
89+ waitForInitialRender &&
90+ expected ?. at ( - 1 ) ?. routeId === initialRoute . id &&
91+ expected . at ( - 1 ) ?. status === 'success'
92+ ) {
93+ waitForInitialRender = false
94+ initialPublished . resolve ( )
95+ return initialRenderAck
96+ }
97+ return Promise . resolve ( true )
98+ }
99+
100+ const initialLoad = router . load ( )
101+ let navigation : Promise < void > | undefined
102+ try {
103+ await initialPublished
104+ expect ( router . _committed . at ( - 1 ) ?. routeId ) . toBe ( initialRoute . id )
105+ expect ( router . state . resolvedLocation ) . toBeUndefined ( )
106+ expect ( initialRenderAck . status ) . toBe ( 'pending' )
107+
108+ navigation = router . navigate ( { to : '/successor' } )
109+ await successorStarted
110+
111+ expect ( router . state . matches . at ( - 1 ) ) . toMatchObject ( {
112+ routeId : successorRoute . id ,
113+ status : 'pending' ,
114+ context : { destinationContext : 'ready' } ,
115+ } )
116+
117+ successorLoader . resolve ( 'successor data' )
118+ initialRenderAck . resolve ( true )
119+ await Promise . all ( [ initialLoad , navigation ] )
120+ } finally {
121+ successorLoader . resolve ( 'successor data' )
122+ initialRenderAck . resolve ( true )
123+ await Promise . allSettled ( [ initialLoad , navigation ] )
124+ router . startTransition = startTransition
125+ }
126+ } )
127+
58128 test ( 'a rejected pending publication restores the committed lane' , async ( ) => {
59129 const loaderStarted = createControlledPromise < void > ( )
60130 const loaderGate = createControlledPromise < string > ( )
0 commit comments