Skip to content

TanStack: Respect routeOverrides component overrides in stories - #35497

Merged
huang-julien merged 5 commits into
storybookjs:nextfrom
unpunnyfuns:fix/tanstack-react-route-overrides-by-id
Jul 24, 2026
Merged

huang-julien merged 5 commits into
storybookjs:nextfrom
unpunnyfuns:fix/tanstack-react-route-overrides-by-id

Conversation

@unpunnyfuns

@unpunnyfuns unpunnyfuns commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #35465.

What I did

routeOverrides component overrides were silently ignored. The guard in injectStoryComponent looked up the override with the cloned leaf's id getter, which is undefined before init().

The lookup never matched and the story component always replaced the component the override had installed.

The lookup now resolves the original (pre-clone) route id through the duplication map, which is the key users write in routeOverrides.

The second commit applies the unit-test review note from #35465: use vi.fn() instead of fn from storybook/test.

Manual testing

AI disclosure

Root-cause analysis, fix, and tests developed with Claude (Claude Code), reviewed and submitted by me.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Fixed story routeOverrides so injected route components correctly honor overrides after route duplication and during router.load(), including pathless and synthetic route structures.
    • Improved override matching to use the story’s original route identity for consistent behavior across route shapes.
  • New Features

    • Extended RouteOverrideOptions with an optional component override, with improved typing for file-based pre-loader routes.
  • Tests

    • Added regression tests for createStoryRouter applying routeOverrides.
    • Updated tests to use Vitest mocking utilities for clearer assertions.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

TanStack story routing now resolves component overrides using original route identifiers across duplicated, provided, and synthetic route trees. Route override typing, injection logic, and regression tests were updated.

Changes

Route override matching

Layer / File(s) Summary
Component override contract
code/frameworks/tanstack-react/src/routing/types.ts
Adds a typed optional component property to RouteOverrideOptions.
Original route identifier lookup
code/frameworks/tanstack-react/src/routing/duplicate-tree.ts
Adds originalRouteId to map duplicated route instances to their original route IDs.
Component injection and regression coverage
code/frameworks/tanstack-react/src/routing/decorator.tsx, code/frameworks/tanstack-react/src/routing/decorator.test.ts, code/frameworks/tanstack-react/src/routing/duplicate-tree.test.ts
Updates override lookup for duplicated, provided, and plain-options routes, with tests for cloned route components and Vitest mocks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs


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.

The guard in injectStoryComponent that respects a user's component override
looked the override up by the cloned leaf's id getter, which is init-backed
and undefined before createRouter() runs — the lookup always missed and the
story render overwrote the component the override had installed. Resolve the
original (pre-clone) id via the duplication byId map and use it as the key.
…t test

Review feedback on storybookjs#35465: keep plain Vitest unit tests free of the
Storybook test layer.
The plain-options branch builds the story child directly instead of going
through duplicateRouteTree, so a story-supplied component/loader override was
never merged onto it and got dropped. Merge the leaf's override into the
synthetic child, matching the route-instance branches.
RouteOverrideOptions exposed loader/beforeLoad/etc. but not component, even
though a component override is supported. Add the field so stories can override
a route's component without casting.
@unpunnyfuns
unpunnyfuns force-pushed the fix/tanstack-react-route-overrides-by-id branch from cce8a23 to 783345f Compare July 18, 2026 15:13
@huang-julien
huang-julien self-requested a review July 24, 2026 08:51
@huang-julien huang-julien added bug tanstack qa:skip Pull Requests that do not need any QA. (e.g. documentation) patch:yes Bugfix & documentation PR that need to be picked to main branch ci:normal Run our default set of CI jobs (choose this for most PRs). labels Jul 24, 2026
@huang-julien
huang-julien requested a review from a team July 24, 2026 09:11
@huang-julien
huang-julien enabled auto-merge July 24, 2026 09:11
@storybook-app-bot

storybook-app-bot Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Package Benchmarks

Commit: bd94afb, ran on 27 July 2026 at 10:32:38 UTC

The following packages have significant changes to their size or dependencies:

@storybook/builder-webpack5

Before After Difference
Dependency count 186 186 0
Self size 79 KB 79 KB 🚨 +1 B 🚨
Dependency size 35.79 MB 36.18 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/angular

Before After Difference
Dependency count 185 185 0
Self size 160 KB 160 KB 0 B
Dependency size 30.25 MB 30.64 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 185 185 0
Self size 13 KB 13 KB 🚨 +18 B 🚨
Dependency size 31.14 MB 31.53 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 531 531 0
Self size 640 KB 640 KB 🚨 +120 B 🚨
Dependency size 62.47 MB 62.86 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 94 93 🎉 -1 🎉
Self size 1.37 MB 1.37 MB 🚨 +48 B 🚨
Dependency size 23.91 MB 23.84 MB 🎉 -74 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 125 122 🎉 -3 🎉
Self size 29 KB 29 KB 🚨 +18 B 🚨
Dependency size 25.90 MB 24.90 MB 🎉 -994 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 83 83 0
Self size 32 KB 32 KB 🚨 +8 B 🚨
Dependency size 21.23 MB 21.61 MB 🚨 +386 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 272 272 0
Self size 23 KB 23 KB 🚨 +12 B 🚨
Dependency size 48.25 MB 48.64 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 198 198 0
Self size 15 KB 15 KB 0 B
Dependency size 37.05 MB 37.44 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 20 20 0
Self size 54 KB 54 KB 🎉 -22 B 🎉
Dependency size 26.65 MB 27.04 MB 🚨 +386 KB 🚨
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 21 21 0
Self size 56 KB 56 KB 0 B
Dependency size 26.70 MB 27.09 MB 🚨 +386 KB 🚨
Bundle Size Analyzer Link Link

@storybook/tanstack-react

Before After Difference
Dependency count 84 84 0
Self size 113 KB 112 KB 🎉 -367 B 🎉
Dependency size 21.26 MB 21.64 MB 🚨 +386 KB 🚨
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 103 102 🎉 -1 🎉
Self size 34 KB 34 KB 🎉 -37 B 🎉
Dependency size 43.10 MB 43.03 MB 🎉 -74 KB 🎉
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 161 161 0
Self size 19 KB 19 KB 🚨 +25 B 🚨
Dependency size 32.76 MB 33.15 MB 🚨 +392 KB 🚨
Bundle Size Analyzer Link Link

@huang-julien
huang-julien merged commit 52cd3b2 into storybookjs:next Jul 24, 2026
129 checks passed
@ndelangen ndelangen added patch:done Patch/release PRs already cherry-picked to main/release branch and removed patch:yes Bugfix & documentation PR that need to be picked to main branch labels Jul 27, 2026
unpunnyfuns pushed a commit to unpunnyfuns/storybook that referenced this pull request Aug 5, 2026
…act-route-overrides-by-id

TanStack: Respect routeOverrides component overrides in stories
(cherry picked from commit 52cd3b2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:human bug ci:normal Run our default set of CI jobs (choose this for most PRs). patch:done Patch/release PRs already cherry-picked to main/release branch qa:skip Pull Requests that do not need any QA. (e.g. documentation) tanstack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants