Feature Request: The way to render one route with all ancestors in isolation #5832
timofei-iatsenko
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When testing or rendering TanStack Router pages in environments like Storybook or Vitest, we currently import the generated
routeTree.gen.ts, create a router instance, and navigate to the desired page.This works, but it creates a major drawback:
each story (or test) ends up depending on the entire application, because
routeTree.gen.tsimports all routes and components in the app.This causes issues with tools that rely on dependency tracing — for example, Chromatic’s Turbosnap (which re-renders only affected stories based on file changes).
Since every story depends on the full route tree, any small change anywhere in the app triggers a full rebuild and re-verification of all stories.
Why Other Approaches Don’t Work
We tried to isolate pages by constructing route subtrees manually — for example, importing only the page and its layout components.
However, this approach is fragile and hard to maintain, because it requires duplicating what the TanStack Router already does:
Essentially, we need a way to render a route together with its ancestors, but without loading the entire app’s route tree.
What’s Needed
A way to programmatically or declaratively obtain a pruned version of the route tree, limited to a specific route and all its ancestors.
This would allow:
routeTree.gen.ts.Example
In Storybook, we’d like to do something like this:
This would yield a route tree containing only
/dashboard/settingsand its ancestors.Current Workaround
I implemented a custom Vite plugin that does exactly this:
tanstack-routetree-pruner
It intercepts imports of a route file and prunes the tree dynamically based on the requested route (
?treesuffix).While it works, it feels like a workaround — this functionality would be better provided natively by TanStack Router, since the router already has all the information needed to build partial trees.
Summary
In short:
Please consider adding an official way to load or generate a partial/pruned route tree (for a given route and its ancestors).
This would improve testing and Storybook integration, make dependency tracking more efficient, and reduce the need for brittle manual workarounds.
Beta Was this translation helpful? Give feedback.
All reactions