@bleedingdev/modern-js-plugin-tanstack 3.9.0-ultramodern.11 → 3.9.0-ultramodern.13

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 (81) hide show
  1. package/dist/cjs/cli/artifacts.js +2 -1
  2. package/dist/cjs/cli/tanstackTypes/canonicalRoutes.js +7 -7
  3. package/dist/cjs/cli/tanstackTypes/shared.js +0 -14
  4. package/dist/cjs/cli/tanstackTypes/source.js +28 -63
  5. package/dist/cjs/runtime/lifecycle.js +0 -3
  6. package/dist/cjs/runtime/loaderBridge.js +10 -4
  7. package/dist/cjs/runtime/navigation.js +102 -0
  8. package/dist/cjs/runtime/plugin.js +6 -1
  9. package/dist/cjs/runtime/plugin.node.js +81 -63
  10. package/dist/cjs/runtime/routeTree/construction.js +19 -61
  11. package/dist/cjs/runtime/routeTree/loaders.js +1 -1
  12. package/dist/cjs/runtime/routeTree/paths.js +0 -6
  13. package/dist/cjs/runtime/ssrManagedTags.js +2 -12
  14. package/dist/cjs/runtime/utils.js +1 -0
  15. package/dist/cjs/shared/routeDescriptor.js +60 -0
  16. package/dist/esm/cli/artifacts.mjs +2 -1
  17. package/dist/esm/cli/index.mjs +1 -7
  18. package/dist/esm/cli/tanstackTypes/canonicalRoutes.mjs +7 -7
  19. package/dist/esm/cli/tanstackTypes/shared.mjs +1 -9
  20. package/dist/esm/cli/tanstackTypes/source.mjs +29 -64
  21. package/dist/esm/runtime/lifecycle.mjs +1 -1
  22. package/dist/esm/runtime/loaderBridge.mjs +8 -5
  23. package/dist/esm/runtime/navigation.mjs +64 -0
  24. package/dist/esm/runtime/plugin.mjs +6 -1
  25. package/dist/esm/runtime/plugin.node.mjs +83 -65
  26. package/dist/esm/runtime/routeTree/construction.mjs +19 -61
  27. package/dist/esm/runtime/routeTree/loaders.mjs +2 -2
  28. package/dist/esm/runtime/routeTree/paths.mjs +1 -4
  29. package/dist/esm/runtime/ssrManagedTags.mjs +1 -8
  30. package/dist/esm/runtime/utils.mjs +1 -0
  31. package/dist/esm/shared/routeDescriptor.mjs +22 -0
  32. package/dist/esm-node/cli/artifacts.mjs +2 -1
  33. package/dist/esm-node/cli/index.mjs +1 -7
  34. package/dist/esm-node/cli/tanstackTypes/canonicalRoutes.mjs +7 -7
  35. package/dist/esm-node/cli/tanstackTypes/shared.mjs +1 -9
  36. package/dist/esm-node/cli/tanstackTypes/source.mjs +29 -64
  37. package/dist/esm-node/runtime/lifecycle.mjs +1 -1
  38. package/dist/esm-node/runtime/loaderBridge.mjs +8 -5
  39. package/dist/esm-node/runtime/navigation.mjs +65 -0
  40. package/dist/esm-node/runtime/plugin.mjs +6 -1
  41. package/dist/esm-node/runtime/plugin.node.mjs +83 -65
  42. package/dist/esm-node/runtime/routeTree/construction.mjs +19 -61
  43. package/dist/esm-node/runtime/routeTree/loaders.mjs +2 -2
  44. package/dist/esm-node/runtime/routeTree/paths.mjs +1 -4
  45. package/dist/esm-node/runtime/ssrManagedTags.mjs +1 -8
  46. package/dist/esm-node/runtime/utils.mjs +1 -0
  47. package/dist/esm-node/shared/routeDescriptor.mjs +23 -0
  48. package/dist/types/cli/tanstackTypes/shared.d.ts +0 -2
  49. package/dist/types/runtime/lifecycle.d.ts +1 -1
  50. package/dist/types/runtime/loaderBridge.d.ts +1 -0
  51. package/dist/types/runtime/navigation.d.ts +4 -0
  52. package/dist/types/runtime/routeTree/paths.d.ts +0 -2
  53. package/dist/types/runtime/ssrManagedTags.d.ts +0 -1
  54. package/dist/types/runtime/ssrTypes.d.ts +0 -7
  55. package/dist/types/shared/routeDescriptor.d.ts +26 -0
  56. package/package.json +21 -21
  57. package/src/cli/artifacts.ts +6 -1
  58. package/src/cli/tanstackTypes/canonicalRoutes.ts +17 -12
  59. package/src/cli/tanstackTypes/shared.ts +0 -14
  60. package/src/cli/tanstackTypes/source.ts +43 -119
  61. package/src/runtime/lifecycle.ts +0 -1
  62. package/src/runtime/loaderBridge.ts +9 -9
  63. package/src/runtime/navigation.ts +78 -0
  64. package/src/runtime/plugin.node.tsx +111 -91
  65. package/src/runtime/plugin.tsx +6 -0
  66. package/src/runtime/routeTree/construction.ts +32 -112
  67. package/src/runtime/routeTree/loaders.ts +2 -4
  68. package/src/runtime/routeTree/paths.ts +0 -6
  69. package/src/runtime/ssrManagedTags.ts +0 -17
  70. package/src/runtime/ssrTypes.ts +0 -7
  71. package/src/runtime/utils.tsx +1 -0
  72. package/src/shared/routeDescriptor.ts +46 -0
  73. package/tests/router/clientNavigation.ts +13 -0
  74. package/tests/router/generateRouteArtifacts.test.ts +36 -2
  75. package/tests/router/localisedIdentity.test.tsx +7 -2
  76. package/tests/router/prefetchLink.test.tsx +29 -0
  77. package/tests/router/routeHooks.test.ts +2 -1
  78. package/tests/router/serverPlugin.test.ts +150 -0
  79. package/tests/router/tanstackTypes.test.ts +121 -2
  80. package/dist/esm/rslib-runtime~1.mjs +0 -18
  81. package/dist/esm-node/rslib-runtime~0.mjs +0 -19
@@ -31,26 +31,22 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  createRouteTreeFromRouteObjects: ()=>createRouteTreeFromRouteObjects,
32
32
  getModernRouteIdsFromMatches: ()=>getModernRouteIdsFromMatches
33
33
  });
34
- const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
35
34
  const context_namespaceObject = require("@modern-js/runtime/context");
36
35
  const react_router_namespaceObject = require("@tanstack/react-router");
36
+ const routeDescriptor_js_namespaceObject = require("../../shared/routeDescriptor.js");
37
37
  const routeStaticData_js_namespaceObject = require("../../shared/routeStaticData.js");
38
38
  const external_outlet_js_namespaceObject = require("../outlet.js");
39
39
  const external_components_js_namespaceObject = require("./components.js");
40
40
  const external_loaders_js_namespaceObject = require("./loaders.js");
41
- const external_paths_js_namespaceObject = require("./paths.js");
42
41
  const external_staticData_js_namespaceObject = require("./staticData.js");
43
42
  const external_tanstackRoutes_js_namespaceObject = require("./tanstackRoutes.js");
44
- function createRouteFromRouteObject(opts) {
45
- const { options = {}, parent, pathlessFallbackId = 'pathless', routeObject } = opts;
43
+ function createRouteOptions(routeObject, options) {
46
44
  const modernRouteObject = routeObject;
47
45
  const revalidationState = {};
48
46
  const shouldRevalidate = modernRouteObject.shouldRevalidate;
49
47
  const shouldReload = (0, external_loaders_js_namespaceObject.createModernShouldReload)(shouldRevalidate, revalidationState);
50
- const stableFallbackId = routeObject.id || modernRouteObject.file || pathlessFallbackId;
51
48
  const component = (0, external_components_js_namespaceObject.toRouteComponent)(routeObject);
52
49
  const base = {
53
- getParentRoute: ()=>parent,
54
50
  component,
55
51
  pendingComponent: (0, external_components_js_namespaceObject.toPendingComponent)(routeObject),
56
52
  errorComponent: (0, external_components_js_namespaceObject.toErrorComponent)(routeObject),
@@ -71,67 +67,29 @@ function createRouteFromRouteObject(opts) {
71
67
  };
72
68
  if (modernRouteObject.inValidSSRRoute) base.ssr = false;
73
69
  if (shouldReload) base.shouldReload = shouldReload;
74
- if ((0, external_paths_js_namespaceObject.isRouteObjectPathlessLayout)(routeObject)) base.id = stableFallbackId;
75
- else base.path = routeObject.index ? '/' : (0, external_paths_js_namespaceObject.toTanstackPath)(routeObject.path || '');
76
- const route = (0, external_tanstackRoutes_js_namespaceObject.createTanstackRoute)(base);
77
- (0, external_tanstackRoutes_js_namespaceObject.wrapRouteComponentWithModernContext)(route, component, routeObject.id);
78
- const children = routeObject.children;
79
- if (children && children.length > 0) {
80
- const childRoutes = children.map((child, index)=>createRouteFromRouteObject({
81
- options,
82
- parent: route,
83
- pathlessFallbackId: `pathless-${index}`,
84
- routeObject: child
85
- }));
86
- route.addChildren(childRoutes);
87
- }
88
- return route;
70
+ return base;
89
71
  }
90
- function getRootLikeRouteObject(routes) {
91
- return routes.find((route)=>'/' === route.path && !route.index);
72
+ function createRouteFromDescriptor(descriptor, parent, options) {
73
+ const { source, location, children } = descriptor;
74
+ const routeOptions = createRouteOptions(source, options);
75
+ const route = (0, external_tanstackRoutes_js_namespaceObject.createTanstackRoute)({
76
+ ...routeOptions,
77
+ ...location,
78
+ getParentRoute: ()=>parent
79
+ });
80
+ (0, external_tanstackRoutes_js_namespaceObject.wrapRouteComponentWithModernContext)(route, routeOptions.component, source.id);
81
+ if (children.length) route.addChildren(children.map((child)=>createRouteFromDescriptor(child, route, options)));
82
+ return route;
92
83
  }
93
84
  function createRouteTreeFromRouteObjects(routes, options = {}) {
94
- routes = (0, i18n_runtime_extensions_namespaceObject.canonicaliseLocalisedRoutes)(routes);
95
- const rootLikeRoute = getRootLikeRouteObject(routes);
96
- const rootRevalidationState = {};
97
- const rootShouldRevalidate = rootLikeRoute?.shouldRevalidate;
98
- const rootShouldReload = (0, external_loaders_js_namespaceObject.createModernShouldReload)(rootShouldRevalidate, rootRevalidationState);
99
- const rootComponent = rootLikeRoute ? (0, external_components_js_namespaceObject.toRouteComponent)(rootLikeRoute) : void 0;
85
+ const { root, children } = (0, routeDescriptor_js_namespaceObject.describeRouteTree)(routes);
100
86
  const rootRouteOptions = {
101
- component: rootComponent,
102
- pendingComponent: rootLikeRoute ? (0, external_components_js_namespaceObject.toPendingComponent)(rootLikeRoute) : void 0,
103
- errorComponent: rootLikeRoute ? (0, external_components_js_namespaceObject.toErrorComponent)(rootLikeRoute) : void 0,
104
- validateSearch: rootLikeRoute?.validateSearch,
105
- loaderDeps: rootLikeRoute?.loaderDeps,
106
- notFoundComponent: context_namespaceObject.DefaultNotFound,
107
- staticData: (0, routeStaticData_js_namespaceObject.createRouteStaticData)({
108
- modernRouteId: rootLikeRoute?.id,
109
- modernRouteAction: rootLikeRoute?.action,
110
- modernRouteHandle: rootLikeRoute ? (0, external_staticData_js_namespaceObject.mergeModernRouteHandle)(rootLikeRoute) : void 0,
111
- modernRouteHasAction: rootLikeRoute?.hasAction || Boolean(rootLikeRoute?.action),
112
- modernRouteHasClientLoader: rootLikeRoute?.hasClientLoader || void 0 !== rootLikeRoute?.clientData,
113
- modernRouteHasLoader: rootLikeRoute?.hasLoader || 'function' == typeof rootLikeRoute?.loader,
114
- modernRouteIsClientComponent: rootLikeRoute?.isClientComponent,
115
- modernRouteLoader: rootLikeRoute?.loader,
116
- modernRouteShouldRevalidate: rootShouldRevalidate
117
- }),
118
- loader: rootLikeRoute ? (0, external_loaders_js_namespaceObject.wrapRouteObjectLoader)(rootLikeRoute, rootRevalidationState, options) : void 0
87
+ ...root ? createRouteOptions(root, options) : {},
88
+ notFoundComponent: context_namespaceObject.DefaultNotFound
119
89
  };
120
- if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
121
- if (rootLikeRoute?.inValidSSRRoute) rootRouteOptions.ssr = false;
122
90
  const rootRoute = (0, external_tanstackRoutes_js_namespaceObject.createTanstackRootRoute)(rootRouteOptions);
123
- if (rootComponent) rootRoute.options.component = (0, external_outlet_js_namespaceObject.withModernRouteMatchContext)(rootComponent, react_router_namespaceObject.rootRouteId);
124
- const topLevel = rootLikeRoute ? [
125
- ...rootLikeRoute.children || [],
126
- ...routes.filter((route)=>route !== rootLikeRoute)
127
- ] : routes;
128
- const childRoutes = topLevel.map((routeObject, index)=>createRouteFromRouteObject({
129
- options,
130
- parent: rootRoute,
131
- pathlessFallbackId: `pathless-${index}`,
132
- routeObject
133
- }));
134
- rootRoute.addChildren(childRoutes);
91
+ if (rootRouteOptions.component) rootRoute.options.component = (0, external_outlet_js_namespaceObject.withModernRouteMatchContext)(rootRouteOptions.component, react_router_namespaceObject.rootRouteId);
92
+ rootRoute.addChildren(children.map((child)=>createRouteFromDescriptor(child, rootRoute, options)));
135
93
  return rootRoute;
136
94
  }
137
95
  function getModernRouteIdsFromMatches(router) {
@@ -82,7 +82,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
82
82
  if ('function' == typeof modernRoute.lazyImport) try {
83
83
  await modernRoute.lazyImport();
84
84
  } catch {}
85
- const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
85
+ const signal = (0, external_loaderBridge_js_namespaceObject.getLoaderSignal)(ctx);
86
86
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
87
87
  const href = (0, external_loaderBridge_js_namespaceObject.getLoaderHref)(ctx);
88
88
  const request = void 0 !== baseRequest ? new Request(baseRequest, {
@@ -39,17 +39,11 @@ function toTanstackPath(pathname) {
39
39
  return segment;
40
40
  }).join('/');
41
41
  }
42
- function isRouteObjectPathlessLayout(route) {
43
- return !route.path && !route.index;
44
- }
45
42
  __webpack_require__.d(__webpack_exports__, {
46
- isRouteObjectPathlessLayout: ()=>isRouteObjectPathlessLayout,
47
43
  toTanstackPath: ()=>toTanstackPath
48
44
  });
49
- exports.isRouteObjectPathlessLayout = __webpack_exports__.isRouteObjectPathlessLayout;
50
45
  exports.toTanstackPath = __webpack_exports__.toTanstackPath;
51
46
  for(var __rspack_i in __webpack_exports__)if (-1 === [
52
- "isRouteObjectPathlessLayout",
53
47
  "toTanstackPath"
54
48
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
49
  Object.defineProperty(exports, '__esModule', {
@@ -27,13 +27,6 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- async function waitForRouterSerialization(tanstackRouter) {
31
- const serverSsr = tanstackRouter.serverSsr;
32
- if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
33
- await new Promise((resolve)=>{
34
- serverSsr.onSerializationFinished?.(resolve);
35
- });
36
- }
37
30
  function htmlEscapeAttr(value) {
38
31
  return value.replace(/&/g, '&').replace(/"/g, '"');
39
32
  }
@@ -83,20 +76,17 @@ __webpack_require__.d(__webpack_exports__, {
83
76
  attachServerSsrUtils: ()=>attachServerSsrUtils,
84
77
  collectRouterErrors: ()=>collectRouterErrors,
85
78
  createGetSsrHref: ()=>createGetSsrHref,
86
- routerManagedTagsToHtml: ()=>routerManagedTagsToHtml,
87
- waitForRouterSerialization: ()=>waitForRouterSerialization
79
+ routerManagedTagsToHtml: ()=>routerManagedTagsToHtml
88
80
  });
89
81
  exports.attachServerSsrUtils = __webpack_exports__.attachServerSsrUtils;
90
82
  exports.collectRouterErrors = __webpack_exports__.collectRouterErrors;
91
83
  exports.createGetSsrHref = __webpack_exports__.createGetSsrHref;
92
84
  exports.routerManagedTagsToHtml = __webpack_exports__.routerManagedTagsToHtml;
93
- exports.waitForRouterSerialization = __webpack_exports__.waitForRouterSerialization;
94
85
  for(var __rspack_i in __webpack_exports__)if (-1 === [
95
86
  "attachServerSsrUtils",
96
87
  "collectRouterErrors",
97
88
  "createGetSsrHref",
98
- "routerManagedTagsToHtml",
99
- "waitForRouterSerialization"
89
+ "routerManagedTagsToHtml"
100
90
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
101
91
  Object.defineProperty(exports, '__esModule', {
102
92
  value: true
@@ -56,6 +56,7 @@ function withGlobalLayout(Component, globalApp) {
56
56
  function toTanstackRouteObject(route, globalApp) {
57
57
  if ('nested' === route.type) return {
58
58
  modernLocalisedRoute: Reflect.get(route, 'modernLocalisedRoute'),
59
+ isRoot: Reflect.get(route, 'isRoot'),
59
60
  path: route.path,
60
61
  id: route.id,
61
62
  loader: route.loader,
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ describeRouteTree: ()=>describeRouteTree
32
+ });
33
+ const paths_js_namespaceObject = require("../runtime/routeTree/paths.js");
34
+ function describeRouteTree(routes) {
35
+ const root = routes.find((route)=>true === route.isRoot || '/' === route.path && true !== route.index);
36
+ const describe = (route, index)=>({
37
+ source: route,
38
+ location: 0 === (route.path ?? '').length && true !== route.index ? {
39
+ id: route.id || route.file || `pathless-${index}`
40
+ } : {
41
+ path: true === route.index ? '/' : (0, paths_js_namespaceObject.toTanstackPath)(route.path || '')
42
+ },
43
+ hasSplat: Boolean(route.path?.includes('*')),
44
+ children: (route.children ?? []).map(describe)
45
+ });
46
+ return {
47
+ root,
48
+ children: (void 0 !== root ? [
49
+ ...root.children ?? [],
50
+ ...routes.filter((route)=>route !== root)
51
+ ] : routes).map(describe)
52
+ };
53
+ }
54
+ exports.describeRouteTree = __webpack_exports__.describeRouteTree;
55
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
56
+ "describeRouteTree"
57
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
58
+ Object.defineProperty(exports, '__esModule', {
59
+ value: true
60
+ });
@@ -95,9 +95,10 @@ async function generateTanstackRouteArtifacts(opts) {
95
95
  version: opts.version || process.env.MODERN_JS_VERSION || '0.0.0-routes-generate',
96
96
  internalPlugins: utils.INTERNAL_RUNTIME_PLUGINS
97
97
  });
98
- await cli.init({
98
+ const { appContext } = await cli.init({
99
99
  ...runOptions,
100
100
  command: 'build'
101
101
  });
102
+ await appContext.hooks.onBeforeExit.call();
102
103
  }
103
104
  export { generateTanstackRouteArtifacts, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries };
@@ -2,19 +2,13 @@ import node_path from "node:path";
2
2
  import { NESTED_ROUTE_SPEC_FILE, filterRoutesForServer } from "@modern-js/utils";
3
3
  import { generateTanstackRouteArtifacts, writeTanstackRegisterFile, writeTanstackRouterTypesForEntries } from "./artifacts.mjs";
4
4
  import { createTanstackRsbuildRouteSplittingProfile, resolveTanstackRouteCodeSplittingEnabled } from "./routeSplitting.mjs";
5
- import { __webpack_require__ } from "../rslib-runtime~1.mjs";
6
- __webpack_require__.add({
7
- 267 (module) {
8
- module.exports = require("@modern-js/runtime/cli");
9
- }
10
- });
11
5
  const DEFAULT_ROUTES_DIR = 'routes';
12
6
  const DEFAULT_GENERATED_DIR_NAME = 'modern-tanstack';
13
7
  const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
14
8
  let runtimeRouterCli;
15
9
  function getRuntimeRouterCli() {
16
10
  if (runtimeRouterCli) return runtimeRouterCli;
17
- const cli = __webpack_require__(267);
11
+ const cli = require("@modern-js/runtime/cli");
18
12
  if (cli.handleGeneratorEntryCode && cli.getEntrypointRoutesDir && cli.getEntrypointRoutesOwner && cli.updateNestedRoutesSpec) {
19
13
  runtimeRouterCli = cli;
20
14
  return runtimeRouterCli;
@@ -1,3 +1,4 @@
1
+ import { describeRouteTree } from "../../shared/routeDescriptor.mjs";
1
2
  import { toTanstackPath } from "./shared.mjs";
2
3
  const LOCALE_PARAM_SEGMENTS = new Set([
3
4
  ':lang',
@@ -44,11 +45,13 @@ function collectCanonicalRoutesForEntry(routes, options = {}) {
44
45
  const key = toTanstackPath(normalized);
45
46
  if (!canonicalParams.has(key)) canonicalParams.set(key, paramsTypeForCanonicalPath(normalized));
46
47
  };
47
- const visit = (route, parentPath)=>{
48
+ const visit = (descriptor, parentPath)=>{
49
+ const { source: route, children } = descriptor;
48
50
  let currentPath = parentPath;
49
- if ('string' == typeof route.modernCanonicalPath) {
51
+ const canonicalPath = route.modernLocalisedRoute?.canonicalPath ?? route.modernCanonicalPath;
52
+ if ('string' == typeof canonicalPath) {
50
53
  hasI18nSurface = true;
51
- currentPath = normalizeJoined(route.modernCanonicalPath);
54
+ currentPath = canonicalPath ? normalizeJoined(canonicalPath) : '';
52
55
  } else if ('string' == typeof route.path && route.path.length > 0) {
53
56
  const segments = route.path.replace(/\[(.+?)\]/g, ':$1').split('/').filter(Boolean);
54
57
  if (localeParamHeuristic && '' === parentPath && LOCALE_PARAM_SEGMENTS.has(segments[0])) {
@@ -57,16 +60,13 @@ function collectCanonicalRoutesForEntry(routes, options = {}) {
57
60
  }
58
61
  currentPath = segments.length ? normalizeJoined(`${parentPath}/${segments.join('/')}`) : parentPath;
59
62
  }
60
- const children = route.children;
61
63
  if (children && children.length > 0) {
62
64
  for (const child of children)visit(child, currentPath);
63
65
  return;
64
66
  }
65
67
  record(currentPath || '/');
66
68
  };
67
- const rootModern = routes.find((route)=>route.isRoot);
68
- const topLevel = rootModern ? rootModern.children ?? [] : routes;
69
- for (const route of topLevel)visit(route, '');
69
+ for (const route of describeRouteTree(routes).children)visit(route, '');
70
70
  if (!hasI18nSurface || 0 === canonicalParams.size) return null;
71
71
  return Object.fromEntries([
72
72
  ...canonicalParams.entries()
@@ -42,14 +42,6 @@ function pickRouteSearchContractModules(route) {
42
42
  loaderDepsPath: 'string' == typeof loaderDepsPath ? loaderDepsPath : null
43
43
  };
44
44
  }
45
- function isPathlessLayout(route) {
46
- const extras = route;
47
- return 'nested' === extras.type && 'boolean' != typeof extras.index && void 0 === extras.path;
48
- }
49
- function isIndexRoute(route) {
50
- const extras = route;
51
- return 'nested' === extras.type && Boolean(extras.index);
52
- }
53
45
  function createRouteStaticDataSnippet(opts) {
54
46
  const staticData = createRouteStaticData({
55
47
  modernRouteId: opts.modernRouteId && quote(opts.modernRouteId),
@@ -60,4 +52,4 @@ function createRouteStaticDataSnippet(opts) {
60
52
  return entries.length > 0 ? `staticData: createRouteStaticData({\n ${entries.map(([key, value])=>`${key}: ${value},`).join('\n ')}\n }),` : null;
61
53
  }
62
54
  export { toTanstackPath } from "../../runtime/routeTree/paths.mjs";
63
- export { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt };
55
+ export { createRouteStaticDataSnippet, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt };
@@ -1,17 +1,11 @@
1
- import { canonicaliseLocalisedRoutes } from "@modern-js/i18n-runtime-extensions";
2
1
  import { makeLegalIdentifier } from "@modern-js/runtime/cli";
3
2
  import { upath } from "@modern-js/utils";
4
- import { createRouteStaticDataSnippet, isIndexRoute, isPathlessLayout, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt, toTanstackPath } from "./shared.mjs";
3
+ import { describeRouteTree } from "../../shared/routeDescriptor.mjs";
4
+ import { createRouteStaticDataSnippet, normalizeRelativeImport, pickModernLoaderModule, pickRouteSearchContractModules, quote, resolveFileNoExt } from "./shared.mjs";
5
5
  async function generateTanstackRouterTypesSourceForEntry(opts) {
6
- const { appContext, entryName, generatedDirName = 'modern-tanstack', routes: rawRoutes } = opts;
7
- const routes = canonicaliseLocalisedRoutes(rawRoutes);
6
+ const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
8
7
  const outDir = upath.join(appContext.srcDirectory, generatedDirName, entryName);
9
- const rootModern = routes.find((r)=>{
10
- const extras = r;
11
- return r && 'nested' === extras.type && extras.isRoot;
12
- });
13
- const rootExtras = rootModern;
14
- const topLevel = rootModern ? rootExtras?.children || [] : routes;
8
+ const { root: rootModern, children: topLevel } = describeRouteTree(routes);
15
9
  const imports = [];
16
10
  const statements = [];
17
11
  const loaderImportMap = new Map();
@@ -28,9 +22,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
28
22
  let pendingImportName = componentImportMap.get(componentPath);
29
23
  if (!pendingImportName) {
30
24
  pendingImportName = (async ()=>{
31
- const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
32
- if (!resolvedNoExt) return null;
33
- const relImport = normalizeRelativeImport(upath.relative(outDir, resolvedNoExt));
25
+ const relImport = await resolveRouteImport(componentPath);
26
+ if (!relImport) return null;
34
27
  const componentName = `component_${componentIndex++}`;
35
28
  imports.push(`import ${componentName} from ${quote(relImport)};`);
36
29
  return componentName;
@@ -39,14 +32,15 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
39
32
  }
40
33
  return pendingImportName;
41
34
  };
42
- const resolveRouteModuleNoExt = async (aliasedNoExtPath)=>{
35
+ const resolveRouteImport = async (aliasedNoExtPath)=>{
43
36
  const prefix = `${appContext.internalSrcAlias}/`;
44
37
  let absNoExt;
45
38
  if (aliasedNoExtPath.startsWith(prefix)) {
46
39
  const rel = aliasedNoExtPath.slice(prefix.length);
47
40
  absNoExt = upath.join(appContext.srcDirectory, rel);
48
41
  } else absNoExt = upath.isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : upath.join(appContext.srcDirectory, aliasedNoExtPath);
49
- return resolveFileNoExt(absNoExt);
42
+ const resolvedNoExt = await resolveFileNoExt(absNoExt);
43
+ return resolvedNoExt ? normalizeRelativeImport(upath.relative(outDir, resolvedNoExt)) : null;
50
44
  };
51
45
  const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
52
46
  const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
@@ -55,9 +49,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
55
49
  loaderName: existing,
56
50
  actionName: hasAction ? existing.replace(/^loader_/, 'action_') : null
57
51
  };
58
- const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
59
- if (!resolvedNoExt) return null;
60
- const relImport = normalizeRelativeImport(upath.relative(outDir, resolvedNoExt));
52
+ const relImport = await resolveRouteImport(aliasedNoExtPath);
53
+ if (!relImport) return null;
61
54
  const importName = `loader_${loaderIndex++}`;
62
55
  const actionName = hasAction ? importName.replace(/^loader_/, 'action_') : null;
63
56
  if (inline) {
@@ -77,9 +70,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
77
70
  const key = `${exportName}:${aliasedNoExtPath}`;
78
71
  const existing = searchContractImportMap.get(key);
79
72
  if (existing) return existing;
80
- const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
81
- if (!resolvedNoExt) return null;
82
- const relImport = normalizeRelativeImport(upath.relative(outDir, resolvedNoExt));
73
+ const relImport = await resolveRouteImport(aliasedNoExtPath);
74
+ if (!relImport) return null;
83
75
  const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
84
76
  imports.push(`import { ${exportName} as ${importName} } from ${quote(relImport)};`);
85
77
  searchContractImportMap.set(key, importName);
@@ -97,9 +89,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
97
89
  const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
98
90
  return reserveRouteVarName(`route_${base}`);
99
91
  };
100
- const buildRoute = async (opts)=>{
101
- const { parentVar, route } = opts;
102
- const varName = createRouteVarName(route);
92
+ const createRouteOptions = async (route, hasSplat)=>{
103
93
  const routeExtras = route;
104
94
  const loaderInfo = pickModernLoaderModule(route);
105
95
  const routeAction = routeExtras.action;
@@ -109,20 +99,9 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
109
99
  const searchContractInfo = pickRouteSearchContractModules(route);
110
100
  const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
111
101
  const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
112
- const rawPath = routeExtras.path;
113
- const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
114
- const routeOpts = [
115
- `getParentRoute: () => ${parentVar},`
116
- ];
102
+ const routeOpts = [];
117
103
  const componentName = await getImportNameForComponent(routeExtras._component);
118
104
  if (componentName) routeOpts.push(`component: ${componentName},`);
119
- if (isPathlessLayout(route)) {
120
- const id = routeExtras.id;
121
- routeOpts.push(`id: ${quote(id || 'pathless')},`);
122
- } else {
123
- const p = isIndexRoute(route) ? '/' : toTanstackPath(rawPath || '');
124
- routeOpts.push(`path: ${quote(p)},`);
125
- }
126
105
  if (loaderName) routeOpts.push(`loader: modernLoaderToTanstack({ hasSplat: ${hasSplat} }, ${loaderName}),`);
127
106
  if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
128
107
  if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
@@ -132,39 +111,29 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
132
111
  actionName
133
112
  });
134
113
  if (staticDataSnippet) routeOpts.push(staticDataSnippet);
135
- const children = routeExtras.children;
114
+ return routeOpts;
115
+ };
116
+ const buildRoute = async (descriptor, parentVar)=>{
117
+ const { source: route, location, hasSplat, children } = descriptor;
118
+ const varName = createRouteVarName(route);
119
+ const routeOpts = [
120
+ `getParentRoute: () => ${parentVar},`,
121
+ ...Object.entries(location).map(([key, value])=>`${key}: ${quote(value)},`),
122
+ ...await createRouteOptions(route, hasSplat)
123
+ ];
136
124
  const hasChildren = Boolean(children && children.length > 0);
137
125
  const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
138
126
  statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
139
127
  if (children && children.length > 0) {
140
128
  const childVars = [];
141
- for (const child of children)childVars.push(await buildRoute({
142
- parentVar: routeCtorVarName,
143
- route: child
144
- }));
129
+ for (const child of children)childVars.push(await buildRoute(child, routeCtorVarName));
145
130
  statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
146
131
  }
147
132
  return varName;
148
133
  };
149
- const rootLoaderInfo = rootModern ? pickModernLoaderModule(rootModern) : null;
150
- const rootAction = rootExtras?.action;
151
- const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
152
- const rootLoaderName = rootLoaderImports?.loaderName || null;
153
- const rootActionName = rootLoaderImports?.actionName || null;
154
- const rootSearchContractInfo = rootModern ? pickRouteSearchContractModules(rootModern) : null;
155
- const rootValidateSearchName = rootSearchContractInfo?.validateSearchPath ? await getImportNameForSearchContract(rootSearchContractInfo.validateSearchPath, 'validateSearch') : null;
156
- const rootLoaderDepsName = rootSearchContractInfo?.loaderDepsPath ? await getImportNameForSearchContract(rootSearchContractInfo.loaderDepsPath, 'loaderDeps') : null;
157
134
  const topLevelVars = [];
158
- for (const route of topLevel)topLevelVars.push(await buildRoute({
159
- parentVar: 'rootRoute',
160
- route
161
- }));
162
- const rootOpts = [];
163
- const rootComponentName = await getImportNameForComponent(rootExtras?._component);
164
- if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
165
- if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
166
- if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
167
- if (rootLoaderDepsName) rootOpts.push(`loaderDeps: ${rootLoaderDepsName},`);
135
+ for (const route of topLevel)topLevelVars.push(await buildRoute(route, 'rootRoute'));
136
+ const rootOpts = rootModern ? await createRouteOptions(rootModern, false) : [];
168
137
  const routerGenTs = `// This file is auto-generated by Modern.js. Do not edit manually.
169
138
 
170
139
  import {
@@ -181,11 +150,7 @@ ${imports.join('\n')}
181
150
 
182
151
  export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
183
152
  ${rootOpts.join('\n ')}
184
- ${createRouteStaticDataSnippet({
185
- modernRouteId: rootExtras?.id,
186
- loaderName: rootLoaderName,
187
- actionName: rootActionName
188
- }) || ''}
153
+
189
154
  });
190
155
 
191
156
  ${statements.join('\n\n')}
@@ -1 +1 @@
1
- export { applyRouterRuntimeState, applyRouterServerPrepareResult, createRouterRuntimeState, createRouterServerSnapshot, getRouterRuntimeState, getRouterServerSnapshot } from "@modern-js/runtime-extensions/router-state";
1
+ export { applyRouterRuntimeState, applyRouterServerPrepareResult, createRouterServerSnapshot, getRouterRuntimeState, getRouterServerSnapshot } from "@modern-js/runtime-extensions/router-state";
@@ -36,10 +36,13 @@ function mapSplatParamsForModernLoader(params, hasSplat) {
36
36
  return rest;
37
37
  }
38
38
  function getLoaderSignal(ctx) {
39
- const abortSignal = ctx?.abortController?.signal;
40
- if (abortSignal instanceof AbortSignal) return abortSignal;
41
- if (ctx?.signal instanceof AbortSignal) return ctx.signal;
42
- return new AbortController().signal;
39
+ const matchSignal = ctx?.abortController?.signal ?? ctx?.signal;
40
+ const requestSignal = ctx?.context?.request?.signal;
41
+ const signals = [
42
+ matchSignal,
43
+ requestSignal
44
+ ].filter((signal)=>signal instanceof AbortSignal);
45
+ return AbortSignal.any(signals);
43
46
  }
44
47
  function getLoaderHref(ctx) {
45
48
  if ('string' == typeof ctx?.location) return ctx.location;
@@ -101,4 +104,4 @@ function modernLoaderToTanstack(opts, modernLoader) {
101
104
  };
102
105
  }
103
106
  export { createRouteStaticData } from "../shared/routeStaticData.mjs";
104
- export { getLoaderHref, handleModernLoaderError, handleModernLoaderResult, isAbsoluteUrl, isRedirectResponse, isResponse, isTanstackRedirect, mapSplatParamsForModernLoader, modernLoaderToTanstack, throwTanstackRedirect };
107
+ export { getLoaderHref, getLoaderSignal, handleModernLoaderError, handleModernLoaderResult, isAbsoluteUrl, isRedirectResponse, isResponse, isTanstackRedirect, mapSplatParamsForModernLoader, modernLoaderToTanstack, throwTanstackRedirect };
@@ -0,0 +1,64 @@
1
+ import { Link } from "./prefetchLink.mjs";
2
+ function createTanstackNavigation(router) {
3
+ let location;
4
+ let matches;
5
+ let snapshot;
6
+ return {
7
+ Link: Link,
8
+ getSnapshot () {
9
+ const state = router.state;
10
+ if (location !== state.location || void 0 === matches || matches.length !== state.matches.length || matches.some((match, index)=>match.params !== state.matches[index]?.params)) {
11
+ location = state.location;
12
+ matches = state.matches;
13
+ snapshot = {
14
+ location: {
15
+ pathname: location.pathname,
16
+ search: location.searchStr,
17
+ hash: '' !== location.hash ? `#${location.hash.replace(/^#/, '')}` : ''
18
+ },
19
+ params: Object.assign({}, ...matches.map((match)=>match.params))
20
+ };
21
+ }
22
+ return snapshot;
23
+ },
24
+ subscribe (listener) {
25
+ const stops = [
26
+ 'onBeforeNavigate',
27
+ 'onBeforeLoad',
28
+ 'onLoad',
29
+ 'onResolved'
30
+ ].map((event)=>router.subscribe(event, listener));
31
+ return ()=>{
32
+ for (const stop of stops)stop();
33
+ };
34
+ },
35
+ navigate (href, options) {
36
+ return router.navigate({
37
+ to: href,
38
+ replace: options?.replace,
39
+ ...options?.state === void 0 ? {} : {
40
+ state: options.state
41
+ }
42
+ });
43
+ },
44
+ createLinkProps (target) {
45
+ const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
46
+ return {
47
+ to: target.pathname,
48
+ ...void 0 !== target.search ? {
49
+ search: target.search
50
+ } : {},
51
+ ...void 0 !== target.hash && '' !== target.hash ? {
52
+ hash: target.hash
53
+ } : {},
54
+ ...void 0 === target.hashScrollIntoView ? {} : {
55
+ hashScrollIntoView: target.hashScrollIntoView
56
+ },
57
+ ...void 0 === preload ? {} : {
58
+ preload
59
+ }
60
+ };
61
+ }
62
+ };
63
+ }
64
+ export { createTanstackNavigation };
@@ -10,6 +10,7 @@ import { ModernRouterClient, getTanstackSsrHydrationPromise, hasTanstackSsrHydra
10
10
  import { routerProviderRegistryHooks } from "./hooks.mjs";
11
11
  import { wrapTanstackSsrHydrationBoundary } from "./hydrationBoundary.mjs";
12
12
  import { applyRouterRuntimeState } from "./lifecycle.mjs";
13
+ import { createTanstackNavigation } from "./navigation.mjs";
13
14
  import { createTanstackRouteObjects, getMergedRouterConfig, getTanstackRouteConfig, joinBasename } from "./pluginShared.mjs";
14
15
  import { Link } from "./prefetchLink.mjs";
15
16
  import { useMatches } from "./routeHooks.mjs";
@@ -142,10 +143,14 @@ const tanstackRouterPlugin = (userConfig = {})=>{
142
143
  runtimeContext
143
144
  ]);
144
145
  if (!router) return App ? /*#__PURE__*/ jsx(App, {}) : null;
146
+ const navigation = useMemo(()=>createTanstackNavigation(router), [
147
+ router
148
+ ]);
145
149
  const runtimeState = applyRouterRuntimeState(runtimeContext, {
146
150
  framework: 'tanstack',
147
151
  basename: _basename,
148
- instance: router
152
+ instance: router,
153
+ navigation
149
154
  });
150
155
  const lifecycleContext = {
151
156
  framework: 'tanstack',