@storybook/tanstack-react 10.5.4 → 10.5.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.
@@ -55,12 +55,12 @@ function initSourceTree(route, counter) {
55
55
  initSourceTree(child, counter);
56
56
  }
57
57
  function cloneChild(oldRoute, parent, overrides, byId) {
58
- let options = oldRoute.options ?? {}, { id: originalId, getParentRoute: _g, ...rest } = options, override = getOverrideFor(overrides, oldRoute.id), merged = { ...rest, ...override }, cloned = createRoute({
59
- ...!merged.path && originalId != null ? { id: originalId } : {},
58
+ let options = oldRoute.options ?? {}, { id: originalId, getParentRoute: _g, ...rest } = options, override = getOverrideFor(overrides, oldRoute.id), { id: overrideId, ...overrideRest } = override, merged = { ...rest, ...overrideRest }, explicitId = "id" in override ? overrideId : originalId, cloned = createRoute({
59
+ ...!merged.path && explicitId != null ? { id: explicitId } : {},
60
60
  ...merged,
61
61
  getParentRoute: () => parent
62
62
  });
63
- byId.set(oldRoute.id, cloned);
63
+ merged.path && explicitId != null && cloned.update({ id: explicitId }), byId.set(oldRoute.id, cloned);
64
64
  let children = oldRoute.children;
65
65
  if (children?.length) {
66
66
  let clonedChildren = children.map(
@@ -96,6 +96,11 @@ function mountPathFor(route) {
96
96
  }
97
97
  return joinPaths(["/", ...segments]);
98
98
  }
99
+ function originalRouteId(tree, route) {
100
+ for (let [id, cloned] of tree.byId)
101
+ if (cloned === route)
102
+ return id;
103
+ }
99
104
  function resolveStoryLeaf(tree, { path, boundRouteId }) {
100
105
  let { root, byId } = tree;
101
106
  if (path) {
@@ -198,7 +203,7 @@ function resolveTree(Story, context) {
198
203
  path: routerParameters.path,
199
204
  boundRouteId: resolvedRoute && resolvedRoute !== rootRoute ? resolvedRoute.id : void 0
200
205
  });
201
- injectStoryComponent(leaf, Story, routeOverrides, leaf.id);
206
+ injectStoryComponent(leaf, Story, routeOverrides, originalRouteId(tree, leaf) ?? leaf.id);
202
207
  let renderLeaf = ensureMatchableLeaf(tree, leaf);
203
208
  return { tree, leaf: renderLeaf };
204
209
  }
@@ -208,7 +213,7 @@ function resolveTree(Story, context) {
208
213
  );
209
214
  routerParameterRoute.update({ getParentRoute: () => syntheticRoot2 }), syntheticRoot2.addChildren([routerParameterRoute]);
210
215
  let tree = duplicateRouteTree(syntheticRoot2, { overrides: routeOverrides }), leaf = tree.byId.get(routerParameterRoute.id) ?? tree.root;
211
- injectStoryComponent(leaf, Story, routeOverrides, leaf.id);
216
+ injectStoryComponent(leaf, Story, routeOverrides, routerParameterRoute.id);
212
217
  let renderLeaf = ensureMatchableLeaf(tree, leaf);
213
218
  return { tree, leaf: renderLeaf };
214
219
  }
@@ -218,14 +223,20 @@ function resolveTree(Story, context) {
218
223
  ...plainRouteRest
219
224
  } = plainOptions, syntheticRouteId = plainRoutePath ? void 0 : plainRouteId ?? "storybook-story", syntheticRoot = createRootRoute(
220
225
  routeOverrides?.__root__ ?? {}
221
- ), syntheticChild = createRoute2({
226
+ ), leafOverrideKey = syntheticRouteId ?? plainRoutePath, leafOverride = leafOverrideKey ? routeOverrides?.[leafOverrideKey] ?? {} : {}, syntheticChild = createRoute2({
222
227
  component: () => React.createElement(Story, null),
223
228
  id: syntheticRouteId,
224
229
  path: plainRoutePath,
225
230
  ...plainRouteRest,
231
+ ...leafOverride,
226
232
  getParentRoute: () => syntheticRoot
227
233
  });
228
- return syntheticRoot.addChildren([syntheticChild]), injectStoryComponent(syntheticChild, Story, routeOverrides, syntheticChild.id), {
234
+ return syntheticRoot.addChildren([syntheticChild]), injectStoryComponent(
235
+ syntheticChild,
236
+ Story,
237
+ routeOverrides,
238
+ syntheticRouteId ?? plainRoutePath ?? syntheticChild.id
239
+ ), {
229
240
  tree: { root: syntheticRoot, byId: /* @__PURE__ */ new Map([[syntheticChild.id, syntheticChild]]) },
230
241
  leaf: syntheticChild
231
242
  };
package/dist/index.d.ts CHANGED
@@ -222,6 +222,8 @@ type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | (
222
222
  * Users can override `loader`, `beforeLoad`, etc. for a specific route.
223
223
  */
224
224
  interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
225
+ /** Override the route's component. */
226
+ component?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['component'] | ComponentType : ComponentType;
225
227
  /** Override the route's loader function. */
226
228
  loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
227
229
  /** Override the route's beforeLoad function. */
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  preview_exports
3
- } from "./_browser-chunks/chunk-4W5ZAMIP.js";
3
+ } from "./_browser-chunks/chunk-6UULZFFJ.js";
4
4
  import "./_browser-chunks/chunk-LTDGLEVR.js";
5
5
  import "./_browser-chunks/chunk-4BE7D4DS.js";
6
6
 
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_riylifm5vf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_riylifm5vf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_riylifm5vf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_k829kijno9e from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_k829kijno9e from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_k829kijno9e from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_riylifm5vf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_riylifm5vf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_riylifm5vf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_k829kijno9e.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_k829kijno9e.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_k829kijno9e.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_riylifm5vf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_riylifm5vf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_riylifm5vf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_k829kijno9e from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_k829kijno9e from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_k829kijno9e from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_riylifm5vf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_riylifm5vf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_riylifm5vf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_k829kijno9e.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_k829kijno9e.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_k829kijno9e.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -360,16 +360,17 @@ function moduleInterceptionPlugin({
360
360
  enforce: "pre",
361
361
  resolveId: {
362
362
  order: "pre",
363
- handler(id, importer) {
363
+ async handler(id, importer) {
364
+ let resolveMock = async (mockPath) => await this.resolve(mockPath, importer, { skipSelf: !0 }) ?? mockPath;
364
365
  if ((id === "@tanstack/react-router" || id.startsWith("@tanstack/react-router/")) && importer && !importer.includes("export-mocks"))
365
- return routerMockPath;
366
+ return resolveMock(routerMockPath);
366
367
  if (START_SERVER_MODULES.includes(id) || id === "@tanstack/react-start")
367
- return startMockPath;
368
+ return resolveMock(startMockPath);
368
369
  if (id === "@tanstack/start-storage-context")
369
- return startStorageContextMockPath;
370
+ return resolveMock(startStorageContextMockPath);
370
371
  for (let pattern of INTERCEPTED_PATTERNS)
371
372
  if (id.includes(pattern))
372
- return startMockPath;
373
+ return resolveMock(startMockPath);
373
374
  return null;
374
375
  }
375
376
  },
package/dist/preview.d.ts CHANGED
@@ -2,6 +2,7 @@ import { LoaderFunction, Renderer, DecoratorFunction } from 'storybook/internal/
2
2
  import { applyDecorators as applyDecorators$1 } from '@storybook/react/entry-preview-docs';
3
3
  import { Register, AnyRoute, FileRoutesByPath } from '@tanstack/react-router';
4
4
  import { RoutesByPath, RouteOptions, ResolveParams, AnyContext } from '@tanstack/router-core';
5
+ import { ComponentType } from 'react';
5
6
  import { Decorator } from '@storybook/react';
6
7
 
7
8
  /** Union of every registered full path (e.g. `'/' | '/admin/users' | '/$libraryId/$version'`). */
@@ -27,6 +28,8 @@ type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | (
27
28
  * Users can override `loader`, `beforeLoad`, etc. for a specific route.
28
29
  */
29
30
  interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
31
+ /** Override the route's component. */
32
+ component?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['component'] | ComponentType : ComponentType;
30
33
  /** Override the route's loader function. */
31
34
  loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
32
35
  /** Override the route's beforeLoad function. */
package/dist/preview.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  loaders,
4
4
  optimizeDeps,
5
5
  parameters
6
- } from "./_browser-chunks/chunk-4W5ZAMIP.js";
6
+ } from "./_browser-chunks/chunk-6UULZFFJ.js";
7
7
  import "./_browser-chunks/chunk-LTDGLEVR.js";
8
8
  import "./_browser-chunks/chunk-4BE7D4DS.js";
9
9
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/tanstack-react",
3
- "version": "10.5.4",
3
+ "version": "10.5.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.4",
79
- "@storybook/react": "10.5.4",
80
- "@storybook/react-vite": "10.5.4"
78
+ "@storybook/builder-vite": "10.5.5",
79
+ "@storybook/react": "10.5.5",
80
+ "@storybook/react-vite": "10.5.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.4",
98
+ "storybook": "^10.5.5",
99
99
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
100
100
  },
101
101
  "peerDependenciesMeta": {