@@ -320,6 +320,7 @@ export function useRoutes(
320
320
) ;
321
321
322
322
let { navigator } = React . useContext ( NavigationContext ) ;
323
+ let dataRouterContext = React . useContext ( DataRouterContext ) ;
323
324
let dataRouterStateContext = React . useContext ( DataRouterStateContext ) ;
324
325
let { matches : parentMatches } = React . useContext ( RouteContext ) ;
325
326
let routeMatch = parentMatches [ parentMatches . length - 1 ] ;
@@ -433,7 +434,10 @@ export function useRoutes(
433
434
} )
434
435
) ,
435
436
parentMatches ,
436
- dataRouterStateContext || undefined
437
+ // Only pass along the dataRouterStateContext when we're rendering from the
438
+ // RouterProvider layer. If routes is different then we're rendering from
439
+ // a descendant <Routes> tree
440
+ dataRouterContext ?. router . routes === routes ? dataRouterStateContext : null
437
441
) ;
438
442
439
443
// When a user passes in a `locationArg`, the associated routes need to
@@ -622,7 +626,7 @@ function RenderedRoute({ routeContext, match, children }: RenderedRouteProps) {
622
626
export function _renderMatches (
623
627
matches : RouteMatch [ ] | null ,
624
628
parentMatches : RouteMatch [ ] = [ ] ,
625
- dataRouterState ? : RemixRouter [ "state" ]
629
+ dataRouterState : RemixRouter [ "state" ] | null = null
626
630
) : React . ReactElement | null {
627
631
if ( matches == null ) {
628
632
if ( dataRouterState ?. errors ) {
@@ -644,7 +648,9 @@ export function _renderMatches(
644
648
) ;
645
649
invariant (
646
650
errorIndex >= 0 ,
647
- `Could not find a matching route for the current errors: ${ errors } `
651
+ `Could not find a matching route for errors on route IDs: ${ Object . keys (
652
+ errors
653
+ ) . join ( "," ) } `
648
654
) ;
649
655
renderedMatches = renderedMatches . slice (
650
656
0 ,
0 commit comments