You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The test script should run automatically, but if it doesn’t, you can manually run it using npm test in the terminal.
Routes Setup:
__root: default root route with <Outlet />
/: redirects to /sub/page
/sub/_layout: a layout route with <Outlet /> for /sub with an optional redirect parameter
/sub/_layout/page: contains a link to /sub/else or redirect when present
/sub/_layout/other: identical to /sub/page but lazy-loaded
/sub/_layout/else: the default redirection target when redirect param is missing
The test suite is located in router.test.tsx (Vitest + React Testing Library).
Issue:
When running the tests, the route /sub/_layout/page passes successfully, but /sub/_layout/other fails. Runtime-wise everything seems to be fine.
Interestingly, if I convert /sub/_layout/other from a lazy-loaded route to a standard route, the issue disappears. I also tried preloading the route before rendering, but that didn’t resolve the problem.
The error message when attempting to render /sub/_layout/other is:
Invariant failed: Could not find an active match from "/sub/_layout/other"
Investigation:
I logged the output of router.routesByPath for the failing /sub/_layout/other route. When the route is lazy-loaded, I get the following (with non-essential details removed for clarity):
Notably, the value of _id is '/sub/_layout/sub/_layout/other', which seems incorrect. This might be the reason for the error: Could not find an active match from "/sub/_layout/other".
Which project does this relate to?
Router
Describe the bug
We're encountering an issue when testing lazy-loaded routes using TanStack Router.
I've created a Stackblitz reproduction.
The
test
script should run automatically, but if it doesn’t, you can manually run it usingnpm test
in the terminal.Routes Setup:
__root
: default root route with<Outlet />
/
: redirects to/sub/page
/sub/_layout
: a layout route with<Outlet />
for/sub
with an optionalredirect
parameter/sub/_layout/page
: contains a link to/sub/else
orredirect
when present/sub/_layout/other
: identical to/sub/page
but lazy-loaded/sub/_layout/else
: the default redirection target whenredirect
param is missingThe test suite is located in
router.test.tsx
(Vitest + React Testing Library).Issue:
When running the tests, the route
/sub/_layout/page
passes successfully, but/sub/_layout/other
fails. Runtime-wise everything seems to be fine.Interestingly, if I convert
/sub/_layout/other
from a lazy-loaded route to a standard route, the issue disappears. I also tried preloading the route before rendering, but that didn’t resolve the problem.The error message when attempting to render
/sub/_layout/other
is:Investigation:
I logged the output of
router.routesByPath
for the failing/sub/_layout/other
route. When the route is lazy-loaded, I get the following (with non-essential details removed for clarity):Notably, the value of
_id
is'/sub/_layout/sub/_layout/other'
, which seems incorrect. This might be the reason for the error:Could not find an active match from "/sub/_layout/other"
.This issue seems related to #2400
Your Example Website or App
https://stackblitz.com/edit/vitejs-vite-n66i22?file=src%2Froutes%2F__tests__%2Frouter.test.tsx&terminal=test
Steps to Reproduce the Bug or Issue
npm test
/sub/_layout/other
are not passing withInvariant failed: Could not find an active match from "/sub/_layout/other"
other.lazy.tsx
toother.tsx
Expected behavior
A a user I'd expect the tests to work for both standard and lazy-loaded routes but I'm seeing only standard routes tests passing.
Screenshots or Videos
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: