Skip to content

Tanstack-React: Fix pathless layout routes in stories - #35216

Closed
MPiland wants to merge 2 commits into
storybookjs:nextfrom
MPiland:tanstack-pathless-layouts
Closed

MPiland wants to merge 2 commits into
storybookjs:nextfrom
MPiland:tanstack-pathless-layouts

Conversation

@MPiland

@MPiland MPiland commented Jun 18, 2026 •

Copy link
Copy Markdown

Closes #

What I did

Fixes TanStack React stories that use file-route style pathless layout routes, so pure underscore layout routes stay id-only and duplicated story route trees preserve those id-only layout routes. Adds focused unit coverage and a framework template story that reproduces a pathless authenticated layout with nested dynamic routes.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

  1. Generate the TanStack React Router sandbox:
    yarn task sandbox --template tanstack-react-router/default-ts --start-from auto
  2. Start the generated sandbox Storybook:
    cd ../storybook-sandboxes/tanstack-react-router-default-ts && yarn storybook
  3. Open the PathlessLayoutRoutes / Preserves pathless layout route state story.
  4. Verify the story renders the pathless layout, nested race layout, route context text pathless route context, and route params text dragonborn:dragonborn.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make 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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pathless layout routes to emit the correct route configuration and preserve route context/state across nested routes.
    • Improved route cloning/duplication so pathless layout routes are represented consistently (id-only) without duplicate registration.
  • Tests
    • Added/expanded Vitest coverage for pathless layout routing and duplicated route tree behavior.
  • Documentation
    • Added a Storybook story to demonstrate and verify pathless layout state preservation through nested routes.

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor
Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","build","dependencies"]

🚫

PR is not labeled with one of: ["ci:normal","ci:merged","ci:daily","ci:docs"]

🚫

PR is not labeled with one of: ["qa:needed","qa:skip","qa:success"]

Generated by 🚫 dangerJS against 85155e6

@MPiland
MPiland marked this pull request as ready for review June 18, 2026 16:32
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e797d610-12e6-475f-b007-e53cecc3f349

📥 Commits

Reviewing files that changed from the base of the PR and between 299c598 and 85155e6.

📒 Files selected for processing (1)
  • code/frameworks/tanstack-react/src/export-mocks/react-router.test.ts

📝 Walkthrough

Walkthrough

Pathless layout routes (path segments starting with _ that normalize to /) are now handled correctly in both the createFileRoute mock and the cloneChild route-cloning logic. createFileRoute emits only an id for these routes without path/fullPath, and cloneChild conditionally applies the original route ID either at creation time (pathless) or via update() (pathed). Unit tests and a new Storybook story verify the behavior end-to-end.

Changes

Pathless Layout Route Support

Layer / File(s) Summary
createFileRoute pathless layout handling
code/frameworks/tanstack-react/src/export-mocks/react-router.ts, code/frameworks/tanstack-react/src/export-mocks/react-router.test.ts
createFileRoute detects pure pathless layout segments (last segment starts with _, normalizedPath === '/') and sets only id without path/fullPath. Test harness mocks storybook/test and storybook/internal/preview-api and asserts the id-only shape for a _layout route.
cloneChild route ID preservation
code/frameworks/tanstack-react/src/routing/duplicate-tree.ts, code/frameworks/tanstack-react/src/routing/duplicate-tree.test.ts
cloneChild now injects id at createRoute time for pathless routes and via post-creation update() for pathed routes. New test validates that a /_authed pathless layout clone has options.path unset and that router.load() produces the correct match ID sequence.
PathlessLayoutRoutes Storybook story
code/frameworks/tanstack-react/template/stories/PathlessLayoutRoutes.stories.tsx
New story builds a nested route tree with a pathless authenticated layout providing sessionLabel via beforeLoad, a race route with dynamic params, and a probe component. The PreservesPathlessLayoutRouteState story asserts that layout headings, route context text, and combined params render correctly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/frameworks/tanstack-react/src/export-mocks/react-router.test.ts`:
- Around line 4-11: The vi.mock() calls for 'storybook/test' and
'storybook/internal/preview-api' are missing the { spy: true } option and have
mock behaviors defined inline. Add { spy: true } as the third argument to both
vi.mock() calls, then move the mock behavior implementations out of the
vi.mock() calls and into a beforeEach block. In the beforeEach block, use
vi.mocked() to get type-safe references to the mocked modules and set up the
return values for the fn function and useEffect function respectively, following
the spy-mocking standards.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aee17ef9-7439-4977-a988-364771d7eee7

📥 Commits

Reviewing files that changed from the base of the PR and between d2400da and 299c598.

📒 Files selected for processing (5)
  • code/frameworks/tanstack-react/src/export-mocks/react-router.test.ts
  • code/frameworks/tanstack-react/src/export-mocks/react-router.ts
  • code/frameworks/tanstack-react/src/routing/duplicate-tree.test.ts
  • code/frameworks/tanstack-react/src/routing/duplicate-tree.ts
  • code/frameworks/tanstack-react/template/stories/PathlessLayoutRoutes.stories.tsx

Comment thread code/frameworks/tanstack-react/src/export-mocks/react-router.test.ts Outdated
@github-actions github-actions Bot added the Stale label Jun 29, 2026
@MPiland

MPiland commented Jul 1, 2026

Copy link
Copy Markdown
Author

@Sidnioulz is it possible to get a review of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants