@storybook/tanstack-react 10.5.0-alpha.3 → 10.5.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,6 @@
1
+ import {
2
+ normalizeFileRoutePath
3
+ } from "./chunk-XKNIZ3MM.js";
1
4
  import {
2
5
  __export
3
6
  } from "./chunk-4BE7D4DS.js";
@@ -131,7 +134,7 @@ function createStoryRouter({
131
134
  context,
132
135
  routerContext
133
136
  }) {
134
- let routerParameters = context.parameters.tanstack?.router ?? {}, { tree, leaf } = resolveTree(Story, context), routeTree = tree.root, inferredPath = routerParameters?.path || leaf.fullPath || routeTree.children?.[0]?.fullPath || "/", resolvedPath = interpolatePath({
137
+ let routerParameters = context.parameters.tanstack?.router ?? {}, { tree, leaf } = resolveTree(Story, context), routeTree = tree.root, inferredPath = routerParameters?.path || leaf.fullPath || (leaf.id ? normalizeFileRoutePath(leaf.id) : void 0) || routeTree.children?.[0]?.fullPath || "/", resolvedPath = interpolatePath({
135
138
  path: inferredPath,
136
139
  params: routerParameters?.params ?? {}
137
140
  }).interpolatedPath, search = routerParameters?.query ? defaultStringifySearch(routerParameters.query) : "";
@@ -172,12 +175,17 @@ function resolveTree(Story, context) {
172
175
  let tree = duplicateRouteTree(syntheticRoot2, { overrides: routeOverrides }), leaf = tree.byId.get(routerParameterRoute.id) ?? tree.root;
173
176
  return injectStoryComponent(leaf, Story, routeOverrides, leaf.id), { tree, leaf };
174
177
  }
175
- let plainOptions = routerParameterRoute ?? {}, syntheticRoot = createRootRoute(
178
+ let plainOptions = routerParameterRoute ?? {}, {
179
+ path: plainRoutePath,
180
+ id: plainRouteId,
181
+ ...plainRouteRest
182
+ } = plainOptions, syntheticRouteId = plainRoutePath ? void 0 : plainRouteId ?? "storybook-story", syntheticRoot = createRootRoute(
176
183
  routeOverrides?.__root__ ?? {}
177
184
  ), syntheticChild = createRoute2({
178
185
  component: () => React.createElement(Story, null),
179
- id: "storybook-story",
180
- ...plainOptions,
186
+ id: syntheticRouteId,
187
+ path: plainRoutePath,
188
+ ...plainRouteRest,
181
189
  getParentRoute: () => syntheticRoot
182
190
  });
183
191
  return syntheticRoot.addChildren([syntheticChild]), injectStoryComponent(syntheticChild, Story, routeOverrides, syntheticChild.id), {
@@ -0,0 +1,19 @@
1
+ // src/routing/path-utils.ts
2
+ var possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
3
+ function removeGroups(s) {
4
+ return s.replace(possiblyNestedRouteGroupPatternRegex, "");
5
+ }
6
+ function removeLayoutSegments(routePath = "/") {
7
+ return routePath.split("/").filter((segment) => !segment.startsWith("_")).join("/");
8
+ }
9
+ var underscoreStartEndRegex = /(^_|_$)/gi, underscoreSlashRegex = /(\/_|_\/)/gi;
10
+ function removeUnderscores(s) {
11
+ return s?.replace(underscoreStartEndRegex, "").replace(underscoreSlashRegex, "/");
12
+ }
13
+ function normalizeFileRoutePath(path) {
14
+ return removeGroups(removeUnderscores(removeLayoutSegments(path)) ?? "") || "/";
15
+ }
16
+
17
+ export {
18
+ normalizeFileRoutePath
19
+ };
@@ -325,7 +325,6 @@ declare const useLoaderDeps: Mock<typeof useLoaderDeps$1>;
325
325
  declare const useRouteContext: Mock<typeof useRouteContext$1>;
326
326
  declare const useCanGoBack: Mock<typeof useCanGoBack$1>;
327
327
  declare const useLinkProps: Mock<typeof useLinkProps$1>;
328
- declare const Outlet: () => null;
329
328
  declare const Navigate: typeof Navigate$1;
330
329
  declare const Link: ({ to, children, ...props }: {
331
330
  to: string;
@@ -341,4 +340,4 @@ declare const Link: ({ to, children, ...props }: {
341
340
  */
342
341
  declare function createFileRoute(path: string): (options: any) => _tanstack_react_router.Route<unknown, _tanstack_router_core.AnyRoute, "/", "/" | `/${any}/`, string, "/" | `/${any}/`, undefined, _tanstack_router_core.ResolveParams<"/">, _tanstack_router_core.AnyContext, _tanstack_router_core.AnyContext, _tanstack_router_core.AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>;
343
342
 
344
- export { Link, Navigate, Outlet, createFileRoute, useBlocker, useCanGoBack, useLinkProps, useLoaderData, useLoaderDeps, useLocation, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch };
343
+ export { Link, Navigate, createFileRoute, useBlocker, useCanGoBack, useLinkProps, useLoaderData, useLoaderDeps, useLocation, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch };
@@ -1,3 +1,6 @@
1
+ import {
2
+ normalizeFileRoutePath
3
+ } from "../_browser-chunks/chunk-XKNIZ3MM.js";
1
4
  import {
2
5
  onNavigate
3
6
  } from "../_browser-chunks/chunk-4CKCBIXI.js";
@@ -27,7 +30,7 @@ var useNavigate = fn(_useNavigate).mockName("@tanstack/react-router::useNavigate
27
30
  "@tanstack/react-router::useRouterState"
28
31
  ), useLoaderData = fn(_useLoaderData).mockName("@tanstack/react-router::useLoaderData"), useLoaderDeps = fn(_useLoaderDeps).mockName("@tanstack/react-router::useLoaderDeps"), useRouteContext = fn(_useRouteContext).mockName(
29
32
  "@tanstack/react-router::useRouteContext"
30
- ), useCanGoBack = fn(_useCanGoBack).mockName("@tanstack/react-router::useCanGoBack"), useLinkProps = fn(_useLinkProps).mockName("@tanstack/react-router::useLinkProps"), Outlet = () => null, Navigate = ({ to, href }) => (useEffect(() => {
33
+ ), useCanGoBack = fn(_useCanGoBack).mockName("@tanstack/react-router::useCanGoBack"), useLinkProps = fn(_useLinkProps).mockName("@tanstack/react-router::useLinkProps"), Navigate = ({ to, href }) => (useEffect(() => {
31
34
  onNavigate({ to: to || href });
32
35
  }, [to, href]), null), Link = ({
33
36
  to,
@@ -48,21 +51,21 @@ var useNavigate = fn(_useNavigate).mockName("@tanstack/react-router::useNavigate
48
51
  );
49
52
  };
50
53
  function createFileRoute(path) {
54
+ let normalizedPath = normalizeFileRoutePath(path);
51
55
  return (options) => createRoute({
52
- path,
56
+ path: normalizedPath,
53
57
  ...options,
54
58
  isRoot: !1
55
59
  }).update({
56
60
  id: path,
57
- path,
58
- fullPath: path
61
+ path: normalizedPath,
62
+ fullPath: normalizedPath
59
63
  // any because tanstack router does that
60
64
  });
61
65
  }
62
66
  export {
63
67
  Link,
64
68
  Navigate,
65
- Outlet,
66
69
  createFileRoute,
67
70
  useBlocker,
68
71
  useCanGoBack,
package/dist/index.d.ts CHANGED
@@ -370,4 +370,4 @@ interface TanStackPreview<T extends AddonTypes, TRoute extends AnyRoute | undefi
370
370
  }>;
371
371
  }
372
372
 
373
- export { type CreateStoryRouteOptions, type DefaultStoryPath, type FrameworkOptions, type IsRoute, type Meta, type Preview, type RouterParameters, type StoryObj, type StoryRouteFileOptions, type StoryRouteOptions, type StorybookConfig, type TanStackParameters, type TanStackPreviewOptions, type TanStackTypes, definePreview };
373
+ export { type CreateStoryRouteOptions, type DefaultStoryPath, type FrameworkOptions, type IsRoute, type Meta, type Preview, type RouterParameters, type StoryObj, type StoryRouteFileOptions, type StoryRouteOptions, type StorybookConfig, type TanStackParameters, type TanStackPreview, type TanStackPreviewOptions, type TanStackTypes, definePreview };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  preview_exports
3
- } from "./_browser-chunks/chunk-73EPJ7AY.js";
3
+ } from "./_browser-chunks/chunk-WQHJSC2D.js";
4
+ import "./_browser-chunks/chunk-XKNIZ3MM.js";
4
5
  import "./_browser-chunks/chunk-4BE7D4DS.js";
5
6
 
6
7
  // src/index.ts
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_0nhffdv299qa from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_0nhffdv299qa from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_0nhffdv299qa from "node:module";
1
+ import CJS_COMPAT_NODE_URL_axsjtcsu0p5 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_axsjtcsu0p5 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_axsjtcsu0p5 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_0nhffdv299qa.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_0nhffdv299qa.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_0nhffdv299qa.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_axsjtcsu0p5.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_axsjtcsu0p5.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_axsjtcsu0p5.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_0nhffdv299qa from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_0nhffdv299qa from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_0nhffdv299qa from "node:module";
1
+ import CJS_COMPAT_NODE_URL_axsjtcsu0p5 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_axsjtcsu0p5 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_axsjtcsu0p5 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_0nhffdv299qa.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_0nhffdv299qa.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_0nhffdv299qa.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_axsjtcsu0p5.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_axsjtcsu0p5.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_axsjtcsu0p5.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/preview.js CHANGED
@@ -3,7 +3,8 @@ import {
3
3
  loaders,
4
4
  optimizeDeps,
5
5
  parameters
6
- } from "./_browser-chunks/chunk-73EPJ7AY.js";
6
+ } from "./_browser-chunks/chunk-WQHJSC2D.js";
7
+ import "./_browser-chunks/chunk-XKNIZ3MM.js";
7
8
  import "./_browser-chunks/chunk-4BE7D4DS.js";
8
9
  export {
9
10
  applyDecorators,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/tanstack-react",
3
- "version": "10.5.0-alpha.3",
3
+ "version": "10.5.0-alpha.5",
4
4
  "description": "Storybook for TanStack (React, Vite): Router and Start ready Storybook framework",
5
5
  "keywords": [
6
6
  "storybook",
@@ -75,9 +75,9 @@
75
75
  "!src/**/*"
76
76
  ],
77
77
  "dependencies": {
78
- "@storybook/builder-vite": "10.5.0-alpha.3",
79
- "@storybook/react": "10.5.0-alpha.3",
80
- "@storybook/react-vite": "10.5.0-alpha.3"
78
+ "@storybook/builder-vite": "10.5.0-alpha.5",
79
+ "@storybook/react": "10.5.0-alpha.5",
80
+ "@storybook/react-vite": "10.5.0-alpha.5"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@tanstack/react-router": "^1.168.10",
@@ -95,7 +95,7 @@
95
95
  "@tanstack/start-client-core": "^1.167.9",
96
96
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
97
97
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
98
- "storybook": "^10.5.0-alpha.3",
98
+ "storybook": "^10.5.0-alpha.5",
99
99
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
100
100
  },
101
101
  "peerDependenciesMeta": {
@@ -14,7 +14,7 @@ const meta = {
14
14
  },
15
15
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16
16
  tags: ['autodocs'],
17
- // More on argTypes: https://storybook.js.org/docs/api/argtypes
17
+ // More on argTypes: https://storybook.js.org/docs/api/arg-types
18
18
  argTypes: {
19
19
  backgroundColor: { control: 'color' },
20
20
  },
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/tanstack-react';
4
+
5
+ import { Outlet, createRootRoute, createRoute } from '@tanstack/react-router';
6
+ import { expect, within } from 'storybook/test';
7
+
8
+ // Regression coverage for https://github.com/storybookjs/storybook/issues/35007
9
+ // `@tanstack/react-router`'s `Outlet` used to be mocked as `() => null`, which
10
+ // silently swallowed any leaf content rendered inside a root layout. These
11
+ // stories assert that both the root layout and the leaf content render.
12
+
13
+ function LeafContent() {
14
+ return <p data-testid="tanstack-outlet-leaf">leaf rendered inside root outlet</p>;
15
+ }
16
+
17
+ const RootRoute = createRootRoute({
18
+ component: () => (
19
+ <div data-testid="tanstack-outlet-root">
20
+ <h1>root layout</h1>
21
+ <Outlet />
22
+ </div>
23
+ ),
24
+ });
25
+
26
+ const LeafRoute = createRoute({
27
+ getParentRoute: () => RootRoute,
28
+ path: '/',
29
+ component: LeafContent,
30
+ });
31
+
32
+ RootRoute.addChildren([LeafRoute]);
33
+
34
+ const meta = {
35
+ component: LeafContent,
36
+ parameters: { layout: 'fullscreen' },
37
+ } satisfies Meta<typeof LeafContent>;
38
+
39
+ export default meta;
40
+
41
+ type Story = StoryObj<typeof meta>;
42
+
43
+ /** Passing the leaf `Route` should render it inside the root layout's `<Outlet />`. */
44
+ export const RendersLeafInsideRootOutlet: Story = {
45
+ parameters: {
46
+ tanstack: { router: { route: LeafRoute } },
47
+ },
48
+ play: async ({ canvasElement }) => {
49
+ const canvas = within(canvasElement);
50
+ await expect(canvas.getByTestId('tanstack-outlet-root')).toBeInTheDocument();
51
+ await expect(
52
+ canvas.getByRole('heading', { level: 1, name: 'root layout' })
53
+ ).toBeInTheDocument();
54
+ await expect(canvas.getByTestId('tanstack-outlet-leaf')).toBeInTheDocument();
55
+ },
56
+ };
57
+
58
+ /** Passing the whole route tree plus an explicit `path` resolves through the same outlet. */
59
+ export const RendersLeafViaRouteTreePath: Story = {
60
+ parameters: {
61
+ tanstack: {
62
+ router: { route: RootRoute, path: '/' },
63
+ },
64
+ },
65
+ play: async ({ canvasElement }) => {
66
+ const canvas = within(canvasElement);
67
+ await expect(canvas.getByTestId('tanstack-outlet-root')).toBeInTheDocument();
68
+ await expect(
69
+ canvas.getByRole('heading', { level: 1, name: 'root layout' })
70
+ ).toBeInTheDocument();
71
+ await expect(canvas.getByTestId('tanstack-outlet-leaf')).toBeInTheDocument();
72
+ },
73
+ };