Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import {
createMemoryHistory,
createRootRoute,
Expand Down Expand Up @@ -34,6 +34,25 @@ function buildAuthedTree(layoutOptions: Record<string, unknown> = {}) {
return { root, layout, dashboard };
}

describe('duplicateRouteTree root options', () => {
it('copies root behavior but never the document shell', () => {
const RootComponent = () => null;
const rootBeforeLoad = vi.fn();
const Shell = ({ children }: { children: unknown }) => children;
const root = createRootRoute({
component: RootComponent,
beforeLoad: rootBeforeLoad,
shellComponent: Shell,
} as any);

const { root: cloned } = duplicateRouteTree(root as any);

expect((cloned as any).options.component).toBe(RootComponent);
expect((cloned as any).options.beforeLoad).toBe(rootBeforeLoad);
expect((cloned as any).options.shellComponent).toBeUndefined();
});
});

describe('duplicateRouteTree with pathless layout routes', () => {
it('preserves a code-based pathless layout (explicit id, no path)', async () => {
const root = createRootRoute();
Expand Down
12 changes: 11 additions & 1 deletion code/frameworks/tanstack-react/src/routing/duplicate-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,17 @@ export function duplicateRouteTree(
// one story is mounted in the same browser session (e.g. HMR, navigation).
// We strip `id` from spread options so TanStack assigns the canonical
// `__root__` id itself.
const { id: _rootId, getParentRoute: _rootGetParent, ...restRoot } = rootOptions;
// `shellComponent` is also stripped: it is TanStack Start's document shell
// (`html`/`head`/`body`), which React refuses to nest inside the story
// canvas and whose head content hoists into the page, hijacking the
// document title from inside a story. All other root behavior (component,
// notFoundComponent, errorComponent, beforeLoad context) is kept.
const {
id: _rootId,
getParentRoute: _rootGetParent,
shellComponent: _rootShell,
...restRoot
} = rootOptions;
const newRoot = createRootRouteWithContext()({
...restRoot,
...rootOverride,
Expand Down
Loading