@bleedingdev/modern-js-plugin-tanstack 3.8.1-ultramodern.1 → 3.8.1-ultramodern.3

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.
Files changed (78) hide show
  1. package/dist/cjs/cli/tanstackTypes/shared.js +8 -6
  2. package/dist/cjs/runtime/clientHydration.js +2 -2
  3. package/dist/cjs/runtime/loaderBridge.js +11 -8
  4. package/dist/cjs/runtime/plugin.js +6 -7
  5. package/dist/cjs/runtime/plugin.node.js +5 -6
  6. package/dist/cjs/runtime/pluginShared.js +2 -3
  7. package/dist/cjs/runtime/routeTree/components.js +1 -1
  8. package/dist/cjs/runtime/routeTree/construction.js +4 -3
  9. package/dist/cjs/runtime/routeTree/loaders.js +7 -43
  10. package/dist/cjs/runtime/routeTree/staticData.js +0 -16
  11. package/dist/cjs/runtime/rsc/client.js +2 -6
  12. package/dist/cjs/runtime/rsc/server.js +2 -6
  13. package/dist/cjs/runtime/submitAction.js +3 -12
  14. package/dist/cjs/runtime/utils.js +2 -7
  15. package/dist/cjs/{runtime/rsc/index.js → shared/routeStaticData.js} +6 -10
  16. package/dist/esm/cli/tanstackTypes/shared.mjs +8 -6
  17. package/dist/esm/runtime/clientHydration.mjs +1 -1
  18. package/dist/esm/runtime/loaderBridge.mjs +2 -8
  19. package/dist/esm/runtime/plugin.mjs +5 -6
  20. package/dist/esm/runtime/plugin.node.mjs +3 -4
  21. package/dist/esm/runtime/pluginShared.mjs +2 -3
  22. package/dist/esm/runtime/routeTree/components.mjs +1 -1
  23. package/dist/esm/runtime/routeTree/construction.mjs +3 -2
  24. package/dist/esm/runtime/routeTree/loaders.mjs +8 -44
  25. package/dist/esm/runtime/routeTree/staticData.mjs +1 -14
  26. package/dist/esm/runtime/rsc/client.mjs +1 -2
  27. package/dist/esm/runtime/rsc/server.mjs +1 -2
  28. package/dist/esm/runtime/submitAction.mjs +1 -10
  29. package/dist/esm/runtime/utils.mjs +2 -7
  30. package/dist/esm/shared/routeStaticData.mjs +4 -0
  31. package/dist/esm-node/cli/tanstackTypes/shared.mjs +8 -6
  32. package/dist/esm-node/runtime/clientHydration.mjs +1 -1
  33. package/dist/esm-node/runtime/loaderBridge.mjs +2 -8
  34. package/dist/esm-node/runtime/plugin.mjs +5 -6
  35. package/dist/esm-node/runtime/plugin.node.mjs +3 -4
  36. package/dist/esm-node/runtime/pluginShared.mjs +2 -3
  37. package/dist/esm-node/runtime/routeTree/components.mjs +1 -1
  38. package/dist/esm-node/runtime/routeTree/construction.mjs +3 -2
  39. package/dist/esm-node/runtime/routeTree/loaders.mjs +8 -44
  40. package/dist/esm-node/runtime/routeTree/staticData.mjs +1 -14
  41. package/dist/esm-node/runtime/rsc/client.mjs +1 -2
  42. package/dist/esm-node/runtime/rsc/server.mjs +1 -2
  43. package/dist/esm-node/runtime/submitAction.mjs +1 -10
  44. package/dist/esm-node/runtime/utils.mjs +2 -7
  45. package/dist/esm-node/shared/routeStaticData.mjs +5 -0
  46. package/dist/types/runtime/loaderBridge.d.ts +17 -13
  47. package/dist/types/runtime/pluginShared.d.ts +1 -3
  48. package/dist/types/runtime/routeTree/components.d.ts +1 -2
  49. package/dist/types/runtime/routeTree/staticData.d.ts +2 -14
  50. package/dist/types/runtime/rsc/client.d.ts +0 -1
  51. package/dist/types/runtime/rsc/server.d.ts +0 -1
  52. package/dist/types/runtime/utils.d.ts +0 -3
  53. package/dist/types/shared/routeStaticData.d.ts +1 -0
  54. package/package.json +9 -9
  55. package/src/cli/tanstackTypes/shared.ts +13 -21
  56. package/src/runtime/loaderBridge.ts +5 -38
  57. package/src/runtime/plugin.node.tsx +2 -3
  58. package/src/runtime/plugin.tsx +4 -5
  59. package/src/runtime/pluginShared.ts +1 -4
  60. package/src/runtime/routeTree/components.ts +2 -5
  61. package/src/runtime/routeTree/construction.ts +3 -2
  62. package/src/runtime/routeTree/loaders.ts +13 -77
  63. package/src/runtime/routeTree/staticData.ts +2 -53
  64. package/src/runtime/rsc/client.tsx +0 -2
  65. package/src/runtime/rsc/server.tsx +0 -2
  66. package/src/runtime/submitAction.ts +1 -7
  67. package/src/runtime/utils.tsx +2 -12
  68. package/src/shared/routeStaticData.ts +7 -0
  69. package/tests/router/cli.test.ts +3 -1
  70. package/dist/cjs/runtime/routeTree.js +0 -46
  71. package/dist/esm/runtime/routeTree.mjs +0 -1
  72. package/dist/esm/runtime/rsc/index.mjs +0 -1
  73. package/dist/esm-node/runtime/routeTree.mjs +0 -2
  74. package/dist/esm-node/runtime/rsc/index.mjs +0 -2
  75. package/dist/types/runtime/routeTree.d.ts +0 -1
  76. package/dist/types/runtime/rsc/index.d.ts +0 -2
  77. package/src/runtime/routeTree.ts +0 -7
  78. package/src/runtime/rsc/index.ts +0 -10
@@ -13,7 +13,7 @@ import { applyRouterRuntimeState } from "./lifecycle.mjs";
13
13
  import { createTanstackRouteObjects, getMergedRouterConfig, getTanstackRouteConfig, joinBasename } from "./pluginShared.mjs";
14
14
  import { Link } from "./prefetchLink.mjs";
15
15
  import { useMatches } from "./routeHooks.mjs";
16
- import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
16
+ import { createRouteTreeFromRouteObjects } from "./routeTree/index.mjs";
17
17
  import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
18
18
  import { getModernTanstackRouterFastDefaults } from "./types.mjs";
19
19
  const tanstackRouterPlugin = (userConfig = {})=>{
@@ -126,7 +126,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
126
126
  if (hasSSRBootstrap && getRouteObjects().length > 0) {
127
127
  const runtimeContext = context;
128
128
  const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
129
- if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
129
+ if (router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
130
130
  }
131
131
  });
132
132
  api.wrapRoot((App)=>{
@@ -156,20 +156,19 @@ const tanstackRouterPlugin = (userConfig = {})=>{
156
156
  router
157
157
  };
158
158
  const hasSSRBootstrap = "u" > typeof window && (Boolean(window.$_TSR) || hasTanstackSsrHydrationRecord(router));
159
- const needsRouterClient = hasSSRBootstrap;
160
- if (needsRouterClient) hooks.onBeforeHydrateRouter.call({
159
+ if (hasSSRBootstrap) hooks.onBeforeHydrateRouter.call({
161
160
  ...lifecycleContext,
162
161
  phase: 'hydrate',
163
162
  router,
164
163
  runtimeContext: runtimeState
165
164
  });
166
- const RouterContent = needsRouterClient ? /*#__PURE__*/ jsx(ModernRouterClient, {
165
+ const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ jsx(ModernRouterClient, {
167
166
  router: router
168
167
  }) : /*#__PURE__*/ jsx(RouterProvider, {
169
168
  router: router
170
169
  });
171
170
  const HydratableRouterContent = wrapTanstackSsrHydrationBoundary(RouterContent, hasSSRBootstrap);
172
- if (needsRouterClient) hooks.onAfterHydrateRouter.call({
171
+ if (hasSSRBootstrap) hooks.onAfterHydrateRouter.call({
173
172
  ...lifecycleContext,
174
173
  phase: 'hydrate',
175
174
  router,
@@ -10,7 +10,7 @@ import { routerProviderRegistryHooks } from "./hooks.mjs";
10
10
  import { wrapTanstackSsrHydrationBoundary } from "./hydrationBoundary.mjs";
11
11
  import { applyRouterServerPrepareResult, createRouterServerSnapshot, getRouterRuntimeState } from "./lifecycle.mjs";
12
12
  import { createTanstackRouteObjects, getTanstackRouteConfig, joinBasename } from "./pluginShared.mjs";
13
- import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree.mjs";
13
+ import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree/index.mjs";
14
14
  import { createTanstackRscServerPayload, handleTanstackRscRedirect } from "./rsc/payloadRouter.mjs";
15
15
  import { getTanstackRscRouter, setTanstackRscRouter, setTanstackRscServerPayload } from "./rsc/payloadStorage.mjs";
16
16
  import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref, routerManagedTagsToHtml, waitForRouterSerialization } from "./ssrManagedTags.mjs";
@@ -24,16 +24,15 @@ const tanstackRouterPlugin = (userConfig = {})=>{
24
24
  api.onBeforeRender(async (context, interrupt)=>{
25
25
  const routeConfig = getTanstackRouteConfig(api, userConfig);
26
26
  const { mergedConfig } = routeConfig;
27
- const serializationAdapters = getGlobalEnableRsc() ? (await import("./rsc/server.mjs")).getTanstackRscSerializationAdapters() : void 0;
28
27
  const enableRsc = getGlobalEnableRsc();
28
+ const serializationAdapters = enableRsc ? (await import("./rsc/server.mjs")).getTanstackRscSerializationAdapters() : void 0;
29
29
  const { basename = '' } = mergedConfig;
30
30
  if (!routeConfig.hasConfiguredRoutes) return;
31
31
  const hooks = api.getHooks();
32
32
  await hooks.onBeforeCreateRoutes.call(context);
33
33
  const modifiedRouteObjects = createTanstackRouteObjects({
34
34
  hooks,
35
- routeConfig,
36
- ssrMode: context.ssrContext?.mode
35
+ routeConfig
37
36
  });
38
37
  if (!modifiedRouteObjects.length) return;
39
38
  const { request, nonce, baseUrl, loaderFailureMode = 'errorBoundary' } = context.ssrContext;
@@ -21,11 +21,10 @@ function getTanstackRouteConfig(api, userConfig) {
21
21
  hasConfiguredRoutes: Boolean(finalRouteConfig.routes) || Boolean(mergedConfig.createRoutes)
22
22
  };
23
23
  }
24
- function createTanstackRouteObjects({ hooks, routeConfig, ssrMode }) {
24
+ function createTanstackRouteObjects({ hooks, routeConfig }) {
25
25
  const { mergedConfig, finalRouteConfig } = routeConfig;
26
26
  const routeObjects = void 0 !== mergedConfig.createRoutes ? mergedConfig.createRoutes() : createTanstackRouteObjectsFromConfig({
27
- routesConfig: finalRouteConfig,
28
- ssrMode
27
+ routesConfig: finalRouteConfig
29
28
  }) ?? [];
30
29
  return hooks.modifyRoutes.call(routeObjects);
31
30
  }
@@ -33,7 +33,7 @@ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
33
33
  Component.preload = load;
34
34
  return Component;
35
35
  }
36
- function toRouteComponent(routeObject, options = {}) {
36
+ function toRouteComponent(routeObject) {
37
37
  const route = routeObject;
38
38
  const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
39
39
  const routeComponent = route.Component || route.component;
@@ -1,10 +1,11 @@
1
1
  import { DefaultNotFound } from "@modern-js/runtime/context";
2
2
  import { rootRouteId } from "@tanstack/react-router";
3
+ import { createRouteStaticData } from "../../shared/routeStaticData.mjs";
3
4
  import { withModernRouteMatchContext } from "../outlet.mjs";
4
5
  import { toErrorComponent, toPendingComponent, toRouteComponent } from "./components.mjs";
5
6
  import { createModernShouldReload, wrapRouteObjectLoader } from "./loaders.mjs";
6
7
  import { isRouteObjectPathlessLayout, toTanstackPath } from "./paths.mjs";
7
- import { createRouteStaticData, mergeModernRouteHandle } from "./staticData.mjs";
8
+ import { mergeModernRouteHandle } from "./staticData.mjs";
8
9
  import { createTanstackRootRoute, createTanstackRoute, wrapRouteComponentWithModernContext } from "./tanstackRoutes.mjs";
9
10
  function createRouteFromRouteObject(opts) {
10
11
  const { options = {}, parent, pathlessFallbackId = 'pathless', routeObject } = opts;
@@ -13,7 +14,7 @@ function createRouteFromRouteObject(opts) {
13
14
  const shouldRevalidate = modernRouteObject.shouldRevalidate;
14
15
  const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
15
16
  const stableFallbackId = routeObject.id || modernRouteObject.file || pathlessFallbackId;
16
- const component = toRouteComponent(routeObject, options);
17
+ const component = toRouteComponent(routeObject);
17
18
  const base = {
18
19
  getParentRoute: ()=>parent,
19
20
  component,
@@ -1,5 +1,4 @@
1
- import { notFound } from "@tanstack/react-router";
2
- import { isRedirectResponse, isResponse, isTanstackRedirect, throwTanstackRedirect } from "../loaderBridge.mjs";
1
+ import { getLoaderHref, handleModernLoaderError, handleModernLoaderResult, mapSplatParamsForModernLoader } from "../loaderBridge.mjs";
3
2
  import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "../rsc/payloadRouter.mjs";
4
3
  function isModernDeferredData(value) {
5
4
  if (!value || 'object' != typeof value) return false;
@@ -10,22 +9,10 @@ function normalizeModernLoaderResult(result) {
10
9
  return isModernDeferredData(result) ? result.data : result;
11
10
  }
12
11
  function normalizeModernLoaderResponse(result) {
13
- if (isResponse(result)) {
14
- if (isRedirectResponse(result)) {
15
- const location = result.headers.get('Location') || '/';
16
- throwTanstackRedirect(location);
17
- }
18
- if (404 === result.status) throw notFound();
19
- }
20
- return normalizeModernLoaderResult(result);
21
- }
22
- function createModernRequest(input, signal) {
23
- return new Request(input, {
24
- signal
25
- });
12
+ return normalizeModernLoaderResult(handleModernLoaderResult(result));
26
13
  }
27
14
  function getModernUrlFromLoaderContext(ctx) {
28
- const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '/';
15
+ const href = getLoaderHref(ctx) || '/';
29
16
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
30
17
  const baseUrl = baseRequest?.url || ("u" > typeof window ? window.origin : 'http://localhost');
31
18
  return new URL(href || '/', baseUrl);
@@ -52,20 +39,6 @@ function createModernShouldReload(shouldRevalidate, state) {
52
39
  return 'boolean' == typeof result ? result : void 0;
53
40
  };
54
41
  }
55
- function isRouteObjectSplatRoute(route) {
56
- return 'string' == typeof route.path && route.path.includes('*');
57
- }
58
- function mapParamsForRouteObjectLoader({ route, params }) {
59
- if (isRouteObjectSplatRoute(route)) {
60
- const { _splat, ...rest } = params;
61
- if (void 0 !== _splat) return {
62
- ...rest,
63
- '*': _splat
64
- };
65
- return rest;
66
- }
67
- return params;
68
- }
69
42
  function wrapRouteObjectLoader(route, revalidationState, options = {}) {
70
43
  const modernRoute = route;
71
44
  const routeLoader = modernRoute.loader;
@@ -78,14 +51,13 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
78
51
  } catch {}
79
52
  const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
80
53
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
81
- const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
54
+ const href = getLoaderHref(ctx);
82
55
  const request = void 0 !== baseRequest ? new Request(baseRequest, {
83
56
  signal
84
- }) : createModernRequest(href, signal);
85
- const params = mapParamsForRouteObjectLoader({
86
- route,
87
- params: ctx.params || {}
57
+ }) : new Request(href, {
58
+ signal
88
59
  });
60
+ const params = mapSplatParamsForModernLoader(ctx.params || {}, 'string' == typeof route.path && route.path.includes('*'));
89
61
  const loadModernData = async ()=>{
90
62
  const result = await routeLoader({
91
63
  request,
@@ -102,15 +74,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
102
74
  });
103
75
  return loadModernData();
104
76
  } catch (err) {
105
- if (isResponse(err)) {
106
- if (isTanstackRedirect(err)) throw err;
107
- if (isRedirectResponse(err)) {
108
- const location = err.headers.get('Location') || '/';
109
- throwTanstackRedirect(location);
110
- }
111
- if (404 === err.status) throw notFound();
112
- }
113
- throw err;
77
+ handleModernLoaderError(err);
114
78
  }
115
79
  };
116
80
  }
@@ -6,17 +6,4 @@ function mergeModernRouteHandle(route) {
6
6
  };
7
7
  return Object.keys(handle).length > 0 ? handle : void 0;
8
8
  }
9
- function createRouteStaticData(opts) {
10
- const staticData = {};
11
- if (opts.modernRouteId) staticData.modernRouteId = opts.modernRouteId;
12
- if (opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
13
- if (opts.modernRouteHandle) staticData.modernRouteHandle = opts.modernRouteHandle;
14
- if (opts.modernRouteHasAction) staticData.modernRouteHasAction = true;
15
- if (opts.modernRouteHasClientLoader) staticData.modernRouteHasClientLoader = true;
16
- if (opts.modernRouteHasLoader) staticData.modernRouteHasLoader = true;
17
- if (opts.modernRouteIsClientComponent) staticData.modernRouteIsClientComponent = true;
18
- if (opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
19
- if (opts.modernRouteShouldRevalidate) staticData.modernRouteShouldRevalidate = opts.modernRouteShouldRevalidate;
20
- return Object.keys(staticData).length > 0 ? staticData : void 0;
21
- }
22
- export { createRouteStaticData, mergeModernRouteHandle };
9
+ export { mergeModernRouteHandle };
@@ -28,6 +28,5 @@ function getTanstackRscSerializationAdapters() {
28
28
  adapter
29
29
  ];
30
30
  }
31
- const rscSerializationAdapter = getTanstackRscSerializationAdapters;
32
31
  export { CompositeComponent } from "./CompositeComponent.mjs";
33
- export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters, rscSerializationAdapter };
32
+ export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters };
@@ -115,7 +115,6 @@ function getTanstackRscSerializationAdapters() {
115
115
  adapter
116
116
  ];
117
117
  }
118
- const rscSerializationAdapter = getTanstackRscSerializationAdapters;
119
118
  function createReadableStreamEmitter() {
120
119
  let closed = false;
121
120
  const queue = [];
@@ -193,4 +192,4 @@ function wrapReadableStream(source, handlers) {
193
192
  });
194
193
  }
195
194
  export { CompositeComponent } from "./CompositeComponent.mjs";
196
- export { createCompositeComponent, getTanstackRscSerializationAdapters, renderServerComponent, rscSerializationAdapter };
195
+ export { createCompositeComponent, getTanstackRscSerializationAdapters, renderServerComponent };
@@ -1,4 +1,5 @@
1
1
  import { formDataToTextPlain, formDataToUrlSearchParams, toFormData } from "./formData.mjs";
2
+ import { isRedirectResponse } from "./loaderBridge.mjs";
2
3
  class RouteActionResponseError extends Error {
3
4
  constructor(response, data){
4
5
  super(`Route action failed with status ${response.status}`);
@@ -22,16 +23,6 @@ function resolveRouteHandlers(router, actionTo) {
22
23
  params: routeParams
23
24
  };
24
25
  }
25
- function isRedirectResponse(value) {
26
- if (!(value instanceof Response)) return false;
27
- return [
28
- 301,
29
- 302,
30
- 303,
31
- 307,
32
- 308
33
- ].includes(value.status);
34
- }
35
26
  async function parseResponseData(response) {
36
27
  if (204 === response.status) return null;
37
28
  const contentType = response.headers.get('Content-Type') || '';
@@ -1,5 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import react from "react";
3
+ import { mergeModernRouteHandle } from "./routeTree/staticData.mjs";
3
4
  function withGlobalLayout(Component, globalApp) {
4
5
  if (!globalApp) return Component;
5
6
  const GlobalLayout = globalApp;
@@ -10,12 +11,6 @@ function withGlobalLayout(Component, globalApp) {
10
11
  });
11
12
  };
12
13
  }
13
- function getRouteHandle(route) {
14
- return {
15
- ...route.handle,
16
- ...'object' == typeof route.config ? route.config?.handle : {}
17
- };
18
- }
19
14
  function toTanstackRouteObject(route, globalApp) {
20
15
  if ('nested' === route.type) return {
21
16
  path: route.path,
@@ -23,7 +18,7 @@ function toTanstackRouteObject(route, globalApp) {
23
18
  loader: route.loader,
24
19
  action: route.action,
25
20
  shouldRevalidate: route.shouldRevalidate,
26
- handle: getRouteHandle(route),
21
+ handle: mergeModernRouteHandle(route) ?? {},
27
22
  index: route.index,
28
23
  hasLoader: route.hasLoader || Boolean(route.loader),
29
24
  hasClientLoader: route.hasClientLoader || Boolean(route.clientData),
@@ -0,0 +1,4 @@
1
+ function createRouteStaticData(opts) {
2
+ return Object.fromEntries(Object.entries(opts).filter(([, value])=>Boolean(value)));
3
+ }
4
+ export { createRouteStaticData };
@@ -1,6 +1,7 @@
1
1
  import "node:module";
2
2
  import { getPathWithoutExt } from "@modern-js/runtime/cli";
3
3
  import { findExists, formatImportPath, slash } from "@modern-js/utils";
4
+ import { createRouteStaticData } from "../../shared/routeStaticData.mjs";
4
5
  const JS_OR_TS_EXTS = [
5
6
  '.js',
6
7
  '.jsx',
@@ -51,12 +52,13 @@ function isIndexRoute(route) {
51
52
  return 'nested' === extras.type && Boolean(extras.index);
52
53
  }
53
54
  function createRouteStaticDataSnippet(opts) {
54
- const staticDataLines = [];
55
- if (opts.modernRouteId) staticDataLines.push(`modernRouteId: ${quote(opts.modernRouteId)},`);
56
- if (opts.loaderName) staticDataLines.push(`modernRouteLoader: ${opts.loaderName},`);
57
- if (opts.actionName) staticDataLines.push(`modernRouteAction: ${opts.actionName},`);
58
- if (!staticDataLines.length) return null;
59
- return `staticData: createRouteStaticData({\n ${staticDataLines.join('\n ')}\n }),`;
55
+ const staticData = createRouteStaticData({
56
+ modernRouteId: opts.modernRouteId && quote(opts.modernRouteId),
57
+ modernRouteLoader: opts.loaderName,
58
+ modernRouteAction: opts.actionName
59
+ });
60
+ const entries = Object.entries(staticData);
61
+ return entries.length > 0 ? `staticData: createRouteStaticData({\n ${entries.map(([key, value])=>`${key}: ${value},`).join('\n ')}\n }),` : null;
60
62
  }
61
63
  export { toTanstackPath } from "../../runtime/routeTree/paths.mjs";
62
64
  export { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt };
@@ -2,7 +2,7 @@ import "node:module";
2
2
  import { RouterProvider } from "@tanstack/react-router";
3
3
  import { createElement } from "react";
4
4
  import { withModernRouteMatchContext } from "./outlet.mjs";
5
- import { pickRouteModuleComponent } from "./routeTree.mjs";
5
+ import { pickRouteModuleComponent } from "./routeTree/index.mjs";
6
6
  const routerHydrationRecords = new WeakMap();
7
7
  const routeModulesKey = '_routeModules';
8
8
  function getCachedRouteModule(routeId) {
@@ -36,13 +36,6 @@ function mapSplatParamsForModernLoader(params, hasSplat) {
36
36
  };
37
37
  return rest;
38
38
  }
39
- function createRouteStaticData(opts) {
40
- const staticData = {};
41
- if ('string' == typeof opts.modernRouteId && opts.modernRouteId.length > 0) staticData.modernRouteId = opts.modernRouteId;
42
- if (void 0 !== opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
43
- if (void 0 !== opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
44
- return staticData;
45
- }
46
39
  function getLoaderSignal(ctx) {
47
40
  const abortSignal = ctx?.abortController?.signal;
48
41
  if (abortSignal instanceof AbortSignal) return abortSignal;
@@ -108,4 +101,5 @@ function modernLoaderToTanstack(opts, modernLoader) {
108
101
  }
109
102
  };
110
103
  }
111
- export { createRouteStaticData, isAbsoluteUrl, isRedirectResponse, isResponse, isTanstackRedirect, mapSplatParamsForModernLoader, modernLoaderToTanstack, throwTanstackRedirect };
104
+ export { createRouteStaticData } from "../shared/routeStaticData.mjs";
105
+ export { getLoaderHref, handleModernLoaderError, handleModernLoaderResult, isAbsoluteUrl, isRedirectResponse, isResponse, isTanstackRedirect, mapSplatParamsForModernLoader, modernLoaderToTanstack, throwTanstackRedirect };
@@ -14,7 +14,7 @@ import { applyRouterRuntimeState } from "./lifecycle.mjs";
14
14
  import { createTanstackRouteObjects, getMergedRouterConfig, getTanstackRouteConfig, joinBasename } from "./pluginShared.mjs";
15
15
  import { Link } from "./prefetchLink.mjs";
16
16
  import { useMatches } from "./routeHooks.mjs";
17
- import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
17
+ import { createRouteTreeFromRouteObjects } from "./routeTree/index.mjs";
18
18
  import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
19
19
  import { getModernTanstackRouterFastDefaults } from "./types.mjs";
20
20
  const tanstackRouterPlugin = (userConfig = {})=>{
@@ -127,7 +127,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
127
127
  if (hasSSRBootstrap && getRouteObjects().length > 0) {
128
128
  const runtimeContext = context;
129
129
  const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
130
- if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
130
+ if (router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
131
131
  }
132
132
  });
133
133
  api.wrapRoot((App)=>{
@@ -157,20 +157,19 @@ const tanstackRouterPlugin = (userConfig = {})=>{
157
157
  router
158
158
  };
159
159
  const hasSSRBootstrap = "u" > typeof window && (Boolean(window.$_TSR) || hasTanstackSsrHydrationRecord(router));
160
- const needsRouterClient = hasSSRBootstrap;
161
- if (needsRouterClient) hooks.onBeforeHydrateRouter.call({
160
+ if (hasSSRBootstrap) hooks.onBeforeHydrateRouter.call({
162
161
  ...lifecycleContext,
163
162
  phase: 'hydrate',
164
163
  router,
165
164
  runtimeContext: runtimeState
166
165
  });
167
- const RouterContent = needsRouterClient ? /*#__PURE__*/ jsx(ModernRouterClient, {
166
+ const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ jsx(ModernRouterClient, {
168
167
  router: router
169
168
  }) : /*#__PURE__*/ jsx(RouterProvider, {
170
169
  router: router
171
170
  });
172
171
  const HydratableRouterContent = wrapTanstackSsrHydrationBoundary(RouterContent, hasSSRBootstrap);
173
- if (needsRouterClient) hooks.onAfterHydrateRouter.call({
172
+ if (hasSSRBootstrap) hooks.onAfterHydrateRouter.call({
174
173
  ...lifecycleContext,
175
174
  phase: 'hydrate',
176
175
  router,
@@ -11,7 +11,7 @@ import { routerProviderRegistryHooks } from "./hooks.mjs";
11
11
  import { wrapTanstackSsrHydrationBoundary } from "./hydrationBoundary.mjs";
12
12
  import { applyRouterServerPrepareResult, createRouterServerSnapshot, getRouterRuntimeState } from "./lifecycle.mjs";
13
13
  import { createTanstackRouteObjects, getTanstackRouteConfig, joinBasename } from "./pluginShared.mjs";
14
- import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree.mjs";
14
+ import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree/index.mjs";
15
15
  import { createTanstackRscServerPayload, handleTanstackRscRedirect } from "./rsc/payloadRouter.mjs";
16
16
  import { getTanstackRscRouter, setTanstackRscRouter, setTanstackRscServerPayload } from "./rsc/payloadStorage.mjs";
17
17
  import { attachServerSsrUtils, collectRouterErrors, createGetSsrHref, routerManagedTagsToHtml, waitForRouterSerialization } from "./ssrManagedTags.mjs";
@@ -25,16 +25,15 @@ const tanstackRouterPlugin = (userConfig = {})=>{
25
25
  api.onBeforeRender(async (context, interrupt)=>{
26
26
  const routeConfig = getTanstackRouteConfig(api, userConfig);
27
27
  const { mergedConfig } = routeConfig;
28
- const serializationAdapters = getGlobalEnableRsc() ? (await import("./rsc/server.mjs")).getTanstackRscSerializationAdapters() : void 0;
29
28
  const enableRsc = getGlobalEnableRsc();
29
+ const serializationAdapters = enableRsc ? (await import("./rsc/server.mjs")).getTanstackRscSerializationAdapters() : void 0;
30
30
  const { basename = '' } = mergedConfig;
31
31
  if (!routeConfig.hasConfiguredRoutes) return;
32
32
  const hooks = api.getHooks();
33
33
  await hooks.onBeforeCreateRoutes.call(context);
34
34
  const modifiedRouteObjects = createTanstackRouteObjects({
35
35
  hooks,
36
- routeConfig,
37
- ssrMode: context.ssrContext?.mode
36
+ routeConfig
38
37
  });
39
38
  if (!modifiedRouteObjects.length) return;
40
39
  const { request, nonce, baseUrl, loaderFailureMode = 'errorBoundary' } = context.ssrContext;
@@ -22,11 +22,10 @@ function getTanstackRouteConfig(api, userConfig) {
22
22
  hasConfiguredRoutes: Boolean(finalRouteConfig.routes) || Boolean(mergedConfig.createRoutes)
23
23
  };
24
24
  }
25
- function createTanstackRouteObjects({ hooks, routeConfig, ssrMode }) {
25
+ function createTanstackRouteObjects({ hooks, routeConfig }) {
26
26
  const { mergedConfig, finalRouteConfig } = routeConfig;
27
27
  const routeObjects = void 0 !== mergedConfig.createRoutes ? mergedConfig.createRoutes() : createTanstackRouteObjectsFromConfig({
28
- routesConfig: finalRouteConfig,
29
- ssrMode
28
+ routesConfig: finalRouteConfig
30
29
  }) ?? [];
31
30
  return hooks.modifyRoutes.call(routeObjects);
32
31
  }
@@ -34,7 +34,7 @@ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
34
34
  Component.preload = load;
35
35
  return Component;
36
36
  }
37
- function toRouteComponent(routeObject, options = {}) {
37
+ function toRouteComponent(routeObject) {
38
38
  const route = routeObject;
39
39
  const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
40
40
  const routeComponent = route.Component || route.component;
@@ -1,11 +1,12 @@
1
1
  import "node:module";
2
2
  import { DefaultNotFound } from "@modern-js/runtime/context";
3
3
  import { rootRouteId } from "@tanstack/react-router";
4
+ import { createRouteStaticData } from "../../shared/routeStaticData.mjs";
4
5
  import { withModernRouteMatchContext } from "../outlet.mjs";
5
6
  import { toErrorComponent, toPendingComponent, toRouteComponent } from "./components.mjs";
6
7
  import { createModernShouldReload, wrapRouteObjectLoader } from "./loaders.mjs";
7
8
  import { isRouteObjectPathlessLayout, toTanstackPath } from "./paths.mjs";
8
- import { createRouteStaticData, mergeModernRouteHandle } from "./staticData.mjs";
9
+ import { mergeModernRouteHandle } from "./staticData.mjs";
9
10
  import { createTanstackRootRoute, createTanstackRoute, wrapRouteComponentWithModernContext } from "./tanstackRoutes.mjs";
10
11
  function createRouteFromRouteObject(opts) {
11
12
  const { options = {}, parent, pathlessFallbackId = 'pathless', routeObject } = opts;
@@ -14,7 +15,7 @@ function createRouteFromRouteObject(opts) {
14
15
  const shouldRevalidate = modernRouteObject.shouldRevalidate;
15
16
  const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
16
17
  const stableFallbackId = routeObject.id || modernRouteObject.file || pathlessFallbackId;
17
- const component = toRouteComponent(routeObject, options);
18
+ const component = toRouteComponent(routeObject);
18
19
  const base = {
19
20
  getParentRoute: ()=>parent,
20
21
  component,
@@ -1,6 +1,5 @@
1
1
  import "node:module";
2
- import { notFound } from "@tanstack/react-router";
3
- import { isRedirectResponse, isResponse, isTanstackRedirect, throwTanstackRedirect } from "../loaderBridge.mjs";
2
+ import { getLoaderHref, handleModernLoaderError, handleModernLoaderResult, mapSplatParamsForModernLoader } from "../loaderBridge.mjs";
4
3
  import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "../rsc/payloadRouter.mjs";
5
4
  function isModernDeferredData(value) {
6
5
  if (!value || 'object' != typeof value) return false;
@@ -11,22 +10,10 @@ function normalizeModernLoaderResult(result) {
11
10
  return isModernDeferredData(result) ? result.data : result;
12
11
  }
13
12
  function normalizeModernLoaderResponse(result) {
14
- if (isResponse(result)) {
15
- if (isRedirectResponse(result)) {
16
- const location = result.headers.get('Location') || '/';
17
- throwTanstackRedirect(location);
18
- }
19
- if (404 === result.status) throw notFound();
20
- }
21
- return normalizeModernLoaderResult(result);
22
- }
23
- function createModernRequest(input, signal) {
24
- return new Request(input, {
25
- signal
26
- });
13
+ return normalizeModernLoaderResult(handleModernLoaderResult(result));
27
14
  }
28
15
  function getModernUrlFromLoaderContext(ctx) {
29
- const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '/';
16
+ const href = getLoaderHref(ctx) || '/';
30
17
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
31
18
  const baseUrl = baseRequest?.url || ("u" > typeof window ? window.origin : 'http://localhost');
32
19
  return new URL(href || '/', baseUrl);
@@ -53,20 +40,6 @@ function createModernShouldReload(shouldRevalidate, state) {
53
40
  return 'boolean' == typeof result ? result : void 0;
54
41
  };
55
42
  }
56
- function isRouteObjectSplatRoute(route) {
57
- return 'string' == typeof route.path && route.path.includes('*');
58
- }
59
- function mapParamsForRouteObjectLoader({ route, params }) {
60
- if (isRouteObjectSplatRoute(route)) {
61
- const { _splat, ...rest } = params;
62
- if (void 0 !== _splat) return {
63
- ...rest,
64
- '*': _splat
65
- };
66
- return rest;
67
- }
68
- return params;
69
- }
70
43
  function wrapRouteObjectLoader(route, revalidationState, options = {}) {
71
44
  const modernRoute = route;
72
45
  const routeLoader = modernRoute.loader;
@@ -79,14 +52,13 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
79
52
  } catch {}
80
53
  const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
81
54
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
82
- const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
55
+ const href = getLoaderHref(ctx);
83
56
  const request = void 0 !== baseRequest ? new Request(baseRequest, {
84
57
  signal
85
- }) : createModernRequest(href, signal);
86
- const params = mapParamsForRouteObjectLoader({
87
- route,
88
- params: ctx.params || {}
58
+ }) : new Request(href, {
59
+ signal
89
60
  });
61
+ const params = mapSplatParamsForModernLoader(ctx.params || {}, 'string' == typeof route.path && route.path.includes('*'));
90
62
  const loadModernData = async ()=>{
91
63
  const result = await routeLoader({
92
64
  request,
@@ -103,15 +75,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
103
75
  });
104
76
  return loadModernData();
105
77
  } catch (err) {
106
- if (isResponse(err)) {
107
- if (isTanstackRedirect(err)) throw err;
108
- if (isRedirectResponse(err)) {
109
- const location = err.headers.get('Location') || '/';
110
- throwTanstackRedirect(location);
111
- }
112
- if (404 === err.status) throw notFound();
113
- }
114
- throw err;
78
+ handleModernLoaderError(err);
115
79
  }
116
80
  };
117
81
  }
@@ -7,17 +7,4 @@ function mergeModernRouteHandle(route) {
7
7
  };
8
8
  return Object.keys(handle).length > 0 ? handle : void 0;
9
9
  }
10
- function createRouteStaticData(opts) {
11
- const staticData = {};
12
- if (opts.modernRouteId) staticData.modernRouteId = opts.modernRouteId;
13
- if (opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
14
- if (opts.modernRouteHandle) staticData.modernRouteHandle = opts.modernRouteHandle;
15
- if (opts.modernRouteHasAction) staticData.modernRouteHasAction = true;
16
- if (opts.modernRouteHasClientLoader) staticData.modernRouteHasClientLoader = true;
17
- if (opts.modernRouteHasLoader) staticData.modernRouteHasLoader = true;
18
- if (opts.modernRouteIsClientComponent) staticData.modernRouteIsClientComponent = true;
19
- if (opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
20
- if (opts.modernRouteShouldRevalidate) staticData.modernRouteShouldRevalidate = opts.modernRouteShouldRevalidate;
21
- return Object.keys(staticData).length > 0 ? staticData : void 0;
22
- }
23
- export { createRouteStaticData, mergeModernRouteHandle };
10
+ export { mergeModernRouteHandle };
@@ -29,6 +29,5 @@ function getTanstackRscSerializationAdapters() {
29
29
  adapter
30
30
  ];
31
31
  }
32
- const rscSerializationAdapter = getTanstackRscSerializationAdapters;
33
32
  export { CompositeComponent } from "./CompositeComponent.mjs";
34
- export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters, rscSerializationAdapter };
33
+ export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters };
@@ -116,7 +116,6 @@ function getTanstackRscSerializationAdapters() {
116
116
  adapter
117
117
  ];
118
118
  }
119
- const rscSerializationAdapter = getTanstackRscSerializationAdapters;
120
119
  function createReadableStreamEmitter() {
121
120
  let closed = false;
122
121
  const queue = [];
@@ -194,4 +193,4 @@ function wrapReadableStream(source, handlers) {
194
193
  });
195
194
  }
196
195
  export { CompositeComponent } from "./CompositeComponent.mjs";
197
- export { createCompositeComponent, getTanstackRscSerializationAdapters, renderServerComponent, rscSerializationAdapter };
196
+ export { createCompositeComponent, getTanstackRscSerializationAdapters, renderServerComponent };