@@ -11,6 +11,7 @@ import {
1111 createRootRoute ,
1212 createRoute ,
1313 createRouter ,
14+ useLoaderData ,
1415 useRouter ,
1516} from '../src'
1617
@@ -741,6 +742,51 @@ test('clears pendingTimeout when match resolves', async () => {
741742 expect ( fooPendingComponentOnMountMock ) . not . toHaveBeenCalled ( )
742743} )
743744
745+ test ( 'useLoaderData retains previous data while route match is pending' , async ( ) => {
746+ const history = createMemoryHistory ( { initialEntries : [ '/app' ] } )
747+ const rootRoute = createRootRoute ( {
748+ component : ( ) => {
749+ const loaderData = useLoaderData ( { from : '/app' } )
750+
751+ return (
752+ < >
753+ < div data-testid = "combined" > { `${ loaderData ( ) . length } :0` } </ div >
754+ < Outlet />
755+ </ >
756+ )
757+ } ,
758+ } )
759+ const appRoute = createRoute ( {
760+ getParentRoute : ( ) => rootRoute ,
761+ path : '/app' ,
762+ loader : ( ) => 'loaded' ,
763+ component : ( ) => < div > App route</ div > ,
764+ } )
765+ const routeTree = rootRoute . addChildren ( [ appRoute ] )
766+ const router = createRouter ( { routeTree, history } )
767+
768+ render ( ( ) => < RouterProvider router = { router } /> )
769+
770+ expect ( await screen . findByTestId ( 'combined' ) ) . toHaveTextContent ( '6:0' )
771+
772+ const appMatch = router . state . matches . find (
773+ ( match ) => match . routeId === '/app' ,
774+ )
775+
776+ expect ( appMatch ) . toBeDefined ( )
777+
778+ if ( ! appMatch ) {
779+ throw new Error ( 'Expected /app match to be active' )
780+ }
781+
782+ router . stores . setPending ( [ { ...appMatch , id : `${ appMatch . id } __pending` } ] )
783+ router . stores . setMatches (
784+ router . state . matches . filter ( ( match ) => match . routeId !== '/app' ) ,
785+ )
786+
787+ expect ( screen . getByTestId ( 'combined' ) ) . toHaveTextContent ( '6:0' )
788+ } )
789+
744790test ( 'cancelMatches after pending timeout' , async ( ) => {
745791 function getPendingComponent ( onMount : ( ) => void ) {
746792 const PendingComponent = ( ) => {
0 commit comments