Tanstack: Add @storybook/tanstack-react package#34403
Merged
Merged
Conversation
…t compatibility in preset configuration
…amework with support for story, routeTree, and instance modes. Introduce helper functions for creating memory routers and update documentation with routing examples.
…y removing unnecessary server type definition and enhancing context and createRouter types for better type safety.
…streamline the Vite setup for the TanStack React framework.
- Added `createServerFnStub` and `resetAllServerFnStubs` for mocking server functions. - Introduced integration tests for server function stubs demonstrating various scenarios. - Updated `preset.ts` to include a Vite plugin for handling server function stubs. - Enhanced `preview.tsx` to reset server function stubs between stories. - Created new story examples showcasing loaders and pathless layouts with mocked data. - Removed outdated router example stories and components.
JReinhold
requested changes
May 4, 2026
Contributor
JReinhold
left a comment
There was a problem hiding this comment.
Awesome job 🎉 Only very small comments, the most important ones being about the Babel dependency.
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…tion.ts Co-authored-by: Jeppe Reinhold <jeppe@chromatic.com>
Co-authored-by: Jeppe Reinhold <jeppe@reinhold.is>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
kylegach
reviewed
May 4, 2026
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
JReinhold
approved these changes
May 5, 2026
Comment on lines
+45
to
+57
| const isTanStackStartPlugin = (p: unknown): boolean => { | ||
| if (Array.isArray(p)) { | ||
| return p.some(isTanStackStartPlugin); | ||
| } | ||
| const pluginRecord = p as Record<string, unknown>; | ||
| return ( | ||
| typeof p === 'object' && | ||
| p !== null && | ||
| 'name' in pluginRecord && | ||
| typeof pluginRecord.name === 'string' && | ||
| (pluginRecord.name.startsWith('tanstack-start') || pluginRecord.name.includes('rsc:')) | ||
| ); | ||
| }; |
Contributor
There was a problem hiding this comment.
SGTM. I'm sure the utility function can be modified to support startsWith/includes
10 tasks
@storybook/tanstack-react package
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#34284
What I did
This PR introduces first-class support for TanStack apps in Storybook via a new
@storybook/tanstack-reactframework integration, including router-aware story rendering, TanStack start and router compatible mocks.Build
Tanstack start plugins removal in the preset file
Tanstack start mostly provide server features and SSR capabilities to tanstack router. Since storybook is client-only, we strip out any tanstack start plugins
Server code elimination
Added server-side code elimination/plugin behavior to prevent server-only modules from breaking browser Storybook runtime.
It is similar to https://github.com/TanStack/router/blob/main/packages/start-plugin-core/src/start-compiler/compiler.ts#L965 but without needing a server environement.
Runtime
createFileRoute
Most tanstack router users uses
createFileRouteto create a file based tanstack route.However, the path is ignored when calling
createFileRoute(route)(options), the implementation will provide it's owncreateFileRouteto force the path being set in the returned route object.Page extraction from route
The implementation provides loader and decorator to extract a page component from a route if the user did not provide a component through the meta or story object.
In most cases, tanstack router page files doesn't export the page component. Only the route itself.
This is a DX improvement and to avoid storybook impacting users project.
Server functions
All server functions are mocked by default, the build-time storybook server code elimination plugins strips out any server code dependency/imports
Types
The framework ships a typed parameter layer that threads route inference through stories end-to-end:
parameters.tanstack.router can be passed to Meta<> to propagate route typing across a story file without repeating the route generic.
This means incorrect route params, unknown override paths, or wrong search shapes are caught at compile time rather than at runtime in the browser.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
react router + start
createFileRoutetoparameters.tanstack.router.routerouteTreetoparameters.tanstack.router.routerouteOverridespathparamsstart additionnal tests
createFileRoutetoparameters.tanstack.router.routerouteTreetoparameters.tanstack.router.routerouteOverridespathparamsCaution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
yarn task --task sandbox --start-from auto --template tanstack-react/default-tsDocumentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-34403-sha-14169208. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-34403-sha-14169208 sandboxor in an existing project withnpx storybook@0.0.0-pr-34403-sha-14169208 upgrade.More information
0.0.0-pr-34403-sha-14169208julien/tanstack141692081777885389)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=34403Summary by CodeRabbit