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

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 (68) 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 +82 -64
  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/utils.js +1 -0
  14. package/dist/cjs/shared/routeDescriptor.js +60 -0
  15. package/dist/esm/cli/artifacts.mjs +2 -1
  16. package/dist/esm/cli/tanstackTypes/canonicalRoutes.mjs +7 -7
  17. package/dist/esm/cli/tanstackTypes/shared.mjs +1 -9
  18. package/dist/esm/cli/tanstackTypes/source.mjs +29 -64
  19. package/dist/esm/runtime/lifecycle.mjs +1 -1
  20. package/dist/esm/runtime/loaderBridge.mjs +8 -5
  21. package/dist/esm/runtime/navigation.mjs +64 -0
  22. package/dist/esm/runtime/plugin.mjs +6 -1
  23. package/dist/esm/runtime/plugin.node.mjs +83 -65
  24. package/dist/esm/runtime/routeTree/construction.mjs +19 -61
  25. package/dist/esm/runtime/routeTree/loaders.mjs +2 -2
  26. package/dist/esm/runtime/routeTree/paths.mjs +1 -4
  27. package/dist/esm/runtime/utils.mjs +1 -0
  28. package/dist/esm/shared/routeDescriptor.mjs +22 -0
  29. package/dist/esm-node/cli/artifacts.mjs +2 -1
  30. package/dist/esm-node/cli/tanstackTypes/canonicalRoutes.mjs +7 -7
  31. package/dist/esm-node/cli/tanstackTypes/shared.mjs +1 -9
  32. package/dist/esm-node/cli/tanstackTypes/source.mjs +29 -64
  33. package/dist/esm-node/runtime/lifecycle.mjs +1 -1
  34. package/dist/esm-node/runtime/loaderBridge.mjs +8 -5
  35. package/dist/esm-node/runtime/navigation.mjs +65 -0
  36. package/dist/esm-node/runtime/plugin.mjs +6 -1
  37. package/dist/esm-node/runtime/plugin.node.mjs +83 -65
  38. package/dist/esm-node/runtime/routeTree/construction.mjs +19 -61
  39. package/dist/esm-node/runtime/routeTree/loaders.mjs +2 -2
  40. package/dist/esm-node/runtime/routeTree/paths.mjs +1 -4
  41. package/dist/esm-node/runtime/utils.mjs +1 -0
  42. package/dist/esm-node/shared/routeDescriptor.mjs +23 -0
  43. package/dist/types/cli/tanstackTypes/shared.d.ts +0 -2
  44. package/dist/types/runtime/lifecycle.d.ts +1 -1
  45. package/dist/types/runtime/loaderBridge.d.ts +1 -0
  46. package/dist/types/runtime/navigation.d.ts +4 -0
  47. package/dist/types/runtime/routeTree/paths.d.ts +0 -2
  48. package/dist/types/shared/routeDescriptor.d.ts +26 -0
  49. package/package.json +12 -12
  50. package/src/cli/artifacts.ts +6 -1
  51. package/src/cli/tanstackTypes/canonicalRoutes.ts +17 -12
  52. package/src/cli/tanstackTypes/shared.ts +0 -14
  53. package/src/cli/tanstackTypes/source.ts +43 -119
  54. package/src/runtime/lifecycle.ts +0 -1
  55. package/src/runtime/loaderBridge.ts +9 -9
  56. package/src/runtime/navigation.ts +78 -0
  57. package/src/runtime/plugin.node.tsx +111 -89
  58. package/src/runtime/plugin.tsx +6 -0
  59. package/src/runtime/routeTree/construction.ts +32 -112
  60. package/src/runtime/routeTree/loaders.ts +2 -4
  61. package/src/runtime/routeTree/paths.ts +0 -6
  62. package/src/runtime/utils.tsx +1 -0
  63. package/src/shared/routeDescriptor.ts +46 -0
  64. package/tests/router/generateRouteArtifacts.test.ts +36 -2
  65. package/tests/router/localisedIdentity.test.tsx +1 -0
  66. package/tests/router/prefetchLink.test.tsx +29 -0
  67. package/tests/router/serverPlugin.test.ts +145 -0
  68. package/tests/router/tanstackTypes.test.ts +120 -2
@@ -139,10 +139,11 @@ async function generateTanstackRouteArtifacts(opts) {
139
139
  version: opts.version || process.env.MODERN_JS_VERSION || '0.0.0-routes-generate',
140
140
  internalPlugins: utils.INTERNAL_RUNTIME_PLUGINS
141
141
  });
142
- await cli.init({
142
+ const { appContext } = await cli.init({
143
143
  ...runOptions,
144
144
  command: 'build'
145
145
  });
146
+ await appContext.hooks.onBeforeExit.call();
146
147
  }
147
148
  exports.generateTanstackRouteArtifacts = __webpack_exports__.generateTanstackRouteArtifacts;
148
149
  exports.writeTanstackRegisterFile = __webpack_exports__.writeTanstackRegisterFile;
@@ -30,6 +30,7 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  collectCanonicalRoutesForEntry: ()=>collectCanonicalRoutesForEntry
32
32
  });
33
+ const routeDescriptor_js_namespaceObject = require("../../shared/routeDescriptor.js");
33
34
  const external_shared_js_namespaceObject = require("./shared.js");
34
35
  const LOCALE_PARAM_SEGMENTS = new Set([
35
36
  ':lang',
@@ -76,11 +77,13 @@ function collectCanonicalRoutesForEntry(routes, options = {}) {
76
77
  const key = (0, external_shared_js_namespaceObject.toTanstackPath)(normalized);
77
78
  if (!canonicalParams.has(key)) canonicalParams.set(key, paramsTypeForCanonicalPath(normalized));
78
79
  };
79
- const visit = (route, parentPath)=>{
80
+ const visit = (descriptor, parentPath)=>{
81
+ const { source: route, children } = descriptor;
80
82
  let currentPath = parentPath;
81
- if ('string' == typeof route.modernCanonicalPath) {
83
+ const canonicalPath = route.modernLocalisedRoute?.canonicalPath ?? route.modernCanonicalPath;
84
+ if ('string' == typeof canonicalPath) {
82
85
  hasI18nSurface = true;
83
- currentPath = normalizeJoined(route.modernCanonicalPath);
86
+ currentPath = canonicalPath ? normalizeJoined(canonicalPath) : '';
84
87
  } else if ('string' == typeof route.path && route.path.length > 0) {
85
88
  const segments = route.path.replace(/\[(.+?)\]/g, ':$1').split('/').filter(Boolean);
86
89
  if (localeParamHeuristic && '' === parentPath && LOCALE_PARAM_SEGMENTS.has(segments[0])) {
@@ -89,16 +92,13 @@ function collectCanonicalRoutesForEntry(routes, options = {}) {
89
92
  }
90
93
  currentPath = segments.length ? normalizeJoined(`${parentPath}/${segments.join('/')}`) : parentPath;
91
94
  }
92
- const children = route.children;
93
95
  if (children && children.length > 0) {
94
96
  for (const child of children)visit(child, currentPath);
95
97
  return;
96
98
  }
97
99
  record(currentPath || '/');
98
100
  };
99
- const rootModern = routes.find((route)=>route.isRoot);
100
- const topLevel = rootModern ? rootModern.children ?? [] : routes;
101
- for (const route of topLevel)visit(route, '');
101
+ for (const route of (0, routeDescriptor_js_namespaceObject.describeRouteTree)(routes).children)visit(route, '');
102
102
  if (!hasI18nSurface || 0 === canonicalParams.size) return null;
103
103
  return Object.fromEntries([
104
104
  ...canonicalParams.entries()
@@ -29,8 +29,6 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  createRouteStaticDataSnippet: ()=>createRouteStaticDataSnippet,
32
- isIndexRoute: ()=>isIndexRoute,
33
- isPathlessLayout: ()=>isPathlessLayout,
34
32
  normalizeRelativeImport: ()=>normalizeRelativeImport,
35
33
  pickModernLoaderModule: ()=>pickModernLoaderModule,
36
34
  pickRouteSearchContractModules: ()=>pickRouteSearchContractModules,
@@ -83,14 +81,6 @@ function pickRouteSearchContractModules(route) {
83
81
  loaderDepsPath: 'string' == typeof loaderDepsPath ? loaderDepsPath : null
84
82
  };
85
83
  }
86
- function isPathlessLayout(route) {
87
- const extras = route;
88
- return 'nested' === extras.type && 'boolean' != typeof extras.index && void 0 === extras.path;
89
- }
90
- function isIndexRoute(route) {
91
- const extras = route;
92
- return 'nested' === extras.type && Boolean(extras.index);
93
- }
94
84
  function createRouteStaticDataSnippet(opts) {
95
85
  const staticData = (0, routeStaticData_js_namespaceObject.createRouteStaticData)({
96
86
  modernRouteId: opts.modernRouteId && quote(opts.modernRouteId),
@@ -101,8 +91,6 @@ function createRouteStaticDataSnippet(opts) {
101
91
  return entries.length > 0 ? `staticData: createRouteStaticData({\n ${entries.map(([key, value])=>`${key}: ${value},`).join('\n ')}\n }),` : null;
102
92
  }
103
93
  exports.createRouteStaticDataSnippet = __webpack_exports__.createRouteStaticDataSnippet;
104
- exports.isIndexRoute = __webpack_exports__.isIndexRoute;
105
- exports.isPathlessLayout = __webpack_exports__.isPathlessLayout;
106
94
  exports.normalizeRelativeImport = __webpack_exports__.normalizeRelativeImport;
107
95
  exports.pickModernLoaderModule = __webpack_exports__.pickModernLoaderModule;
108
96
  exports.pickRouteSearchContractModules = __webpack_exports__.pickRouteSearchContractModules;
@@ -111,8 +99,6 @@ exports.resolveFileNoExt = __webpack_exports__.resolveFileNoExt;
111
99
  exports.toTanstackPath = __webpack_exports__.toTanstackPath;
112
100
  for(var __rspack_i in __webpack_exports__)if (-1 === [
113
101
  "createRouteStaticDataSnippet",
114
- "isIndexRoute",
115
- "isPathlessLayout",
116
102
  "normalizeRelativeImport",
117
103
  "pickModernLoaderModule",
118
104
  "pickRouteSearchContractModules",
@@ -30,20 +30,14 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry
32
32
  });
33
- const i18n_runtime_extensions_namespaceObject = require("@modern-js/i18n-runtime-extensions");
34
33
  const cli_namespaceObject = require("@modern-js/runtime/cli");
35
34
  const utils_namespaceObject = require("@modern-js/utils");
35
+ const routeDescriptor_js_namespaceObject = require("../../shared/routeDescriptor.js");
36
36
  const external_shared_js_namespaceObject = require("./shared.js");
37
37
  async function generateTanstackRouterTypesSourceForEntry(opts) {
38
- const { appContext, entryName, generatedDirName = 'modern-tanstack', routes: rawRoutes } = opts;
39
- const routes = (0, i18n_runtime_extensions_namespaceObject.canonicaliseLocalisedRoutes)(rawRoutes);
38
+ const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
40
39
  const outDir = utils_namespaceObject.upath.join(appContext.srcDirectory, generatedDirName, entryName);
41
- const rootModern = routes.find((r)=>{
42
- const extras = r;
43
- return r && 'nested' === extras.type && extras.isRoot;
44
- });
45
- const rootExtras = rootModern;
46
- const topLevel = rootModern ? rootExtras?.children || [] : routes;
40
+ const { root: rootModern, children: topLevel } = (0, routeDescriptor_js_namespaceObject.describeRouteTree)(routes);
47
41
  const imports = [];
48
42
  const statements = [];
49
43
  const loaderImportMap = new Map();
@@ -60,9 +54,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
60
54
  let pendingImportName = componentImportMap.get(componentPath);
61
55
  if (!pendingImportName) {
62
56
  pendingImportName = (async ()=>{
63
- const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
64
- if (!resolvedNoExt) return null;
65
- const relImport = (0, external_shared_js_namespaceObject.normalizeRelativeImport)(utils_namespaceObject.upath.relative(outDir, resolvedNoExt));
57
+ const relImport = await resolveRouteImport(componentPath);
58
+ if (!relImport) return null;
66
59
  const componentName = `component_${componentIndex++}`;
67
60
  imports.push(`import ${componentName} from ${(0, external_shared_js_namespaceObject.quote)(relImport)};`);
68
61
  return componentName;
@@ -71,14 +64,15 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
71
64
  }
72
65
  return pendingImportName;
73
66
  };
74
- const resolveRouteModuleNoExt = async (aliasedNoExtPath)=>{
67
+ const resolveRouteImport = async (aliasedNoExtPath)=>{
75
68
  const prefix = `${appContext.internalSrcAlias}/`;
76
69
  let absNoExt;
77
70
  if (aliasedNoExtPath.startsWith(prefix)) {
78
71
  const rel = aliasedNoExtPath.slice(prefix.length);
79
72
  absNoExt = utils_namespaceObject.upath.join(appContext.srcDirectory, rel);
80
73
  } else absNoExt = utils_namespaceObject.upath.isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : utils_namespaceObject.upath.join(appContext.srcDirectory, aliasedNoExtPath);
81
- return (0, external_shared_js_namespaceObject.resolveFileNoExt)(absNoExt);
74
+ const resolvedNoExt = await (0, external_shared_js_namespaceObject.resolveFileNoExt)(absNoExt);
75
+ return resolvedNoExt ? (0, external_shared_js_namespaceObject.normalizeRelativeImport)(utils_namespaceObject.upath.relative(outDir, resolvedNoExt)) : null;
82
76
  };
83
77
  const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
84
78
  const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
@@ -87,9 +81,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
87
81
  loaderName: existing,
88
82
  actionName: hasAction ? existing.replace(/^loader_/, 'action_') : null
89
83
  };
90
- const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
91
- if (!resolvedNoExt) return null;
92
- const relImport = (0, external_shared_js_namespaceObject.normalizeRelativeImport)(utils_namespaceObject.upath.relative(outDir, resolvedNoExt));
84
+ const relImport = await resolveRouteImport(aliasedNoExtPath);
85
+ if (!relImport) return null;
93
86
  const importName = `loader_${loaderIndex++}`;
94
87
  const actionName = hasAction ? importName.replace(/^loader_/, 'action_') : null;
95
88
  if (inline) {
@@ -109,9 +102,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
109
102
  const key = `${exportName}:${aliasedNoExtPath}`;
110
103
  const existing = searchContractImportMap.get(key);
111
104
  if (existing) return existing;
112
- const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
113
- if (!resolvedNoExt) return null;
114
- const relImport = (0, external_shared_js_namespaceObject.normalizeRelativeImport)(utils_namespaceObject.upath.relative(outDir, resolvedNoExt));
105
+ const relImport = await resolveRouteImport(aliasedNoExtPath);
106
+ if (!relImport) return null;
115
107
  const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
116
108
  imports.push(`import { ${exportName} as ${importName} } from ${(0, external_shared_js_namespaceObject.quote)(relImport)};`);
117
109
  searchContractImportMap.set(key, importName);
@@ -129,9 +121,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
129
121
  const base = id ? (0, cli_namespaceObject.makeLegalIdentifier)(id) : `r_${routeIndex++}`;
130
122
  return reserveRouteVarName(`route_${base}`);
131
123
  };
132
- const buildRoute = async (opts)=>{
133
- const { parentVar, route } = opts;
134
- const varName = createRouteVarName(route);
124
+ const createRouteOptions = async (route, hasSplat)=>{
135
125
  const routeExtras = route;
136
126
  const loaderInfo = (0, external_shared_js_namespaceObject.pickModernLoaderModule)(route);
137
127
  const routeAction = routeExtras.action;
@@ -141,20 +131,9 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
141
131
  const searchContractInfo = (0, external_shared_js_namespaceObject.pickRouteSearchContractModules)(route);
142
132
  const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
143
133
  const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
144
- const rawPath = routeExtras.path;
145
- const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
146
- const routeOpts = [
147
- `getParentRoute: () => ${parentVar},`
148
- ];
134
+ const routeOpts = [];
149
135
  const componentName = await getImportNameForComponent(routeExtras._component);
150
136
  if (componentName) routeOpts.push(`component: ${componentName},`);
151
- if ((0, external_shared_js_namespaceObject.isPathlessLayout)(route)) {
152
- const id = routeExtras.id;
153
- routeOpts.push(`id: ${(0, external_shared_js_namespaceObject.quote)(id || 'pathless')},`);
154
- } else {
155
- const p = (0, external_shared_js_namespaceObject.isIndexRoute)(route) ? '/' : (0, external_shared_js_namespaceObject.toTanstackPath)(rawPath || '');
156
- routeOpts.push(`path: ${(0, external_shared_js_namespaceObject.quote)(p)},`);
157
- }
158
137
  if (loaderName) routeOpts.push(`loader: modernLoaderToTanstack({ hasSplat: ${hasSplat} }, ${loaderName}),`);
159
138
  if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
160
139
  if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
@@ -164,39 +143,29 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
164
143
  actionName
165
144
  });
166
145
  if (staticDataSnippet) routeOpts.push(staticDataSnippet);
167
- const children = routeExtras.children;
146
+ return routeOpts;
147
+ };
148
+ const buildRoute = async (descriptor, parentVar)=>{
149
+ const { source: route, location, hasSplat, children } = descriptor;
150
+ const varName = createRouteVarName(route);
151
+ const routeOpts = [
152
+ `getParentRoute: () => ${parentVar},`,
153
+ ...Object.entries(location).map(([key, value])=>`${key}: ${(0, external_shared_js_namespaceObject.quote)(value)},`),
154
+ ...await createRouteOptions(route, hasSplat)
155
+ ];
168
156
  const hasChildren = Boolean(children && children.length > 0);
169
157
  const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
170
158
  statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
171
159
  if (children && children.length > 0) {
172
160
  const childVars = [];
173
- for (const child of children)childVars.push(await buildRoute({
174
- parentVar: routeCtorVarName,
175
- route: child
176
- }));
161
+ for (const child of children)childVars.push(await buildRoute(child, routeCtorVarName));
177
162
  statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
178
163
  }
179
164
  return varName;
180
165
  };
181
- const rootLoaderInfo = rootModern ? (0, external_shared_js_namespaceObject.pickModernLoaderModule)(rootModern) : null;
182
- const rootAction = rootExtras?.action;
183
- const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
184
- const rootLoaderName = rootLoaderImports?.loaderName || null;
185
- const rootActionName = rootLoaderImports?.actionName || null;
186
- const rootSearchContractInfo = rootModern ? (0, external_shared_js_namespaceObject.pickRouteSearchContractModules)(rootModern) : null;
187
- const rootValidateSearchName = rootSearchContractInfo?.validateSearchPath ? await getImportNameForSearchContract(rootSearchContractInfo.validateSearchPath, 'validateSearch') : null;
188
- const rootLoaderDepsName = rootSearchContractInfo?.loaderDepsPath ? await getImportNameForSearchContract(rootSearchContractInfo.loaderDepsPath, 'loaderDeps') : null;
189
166
  const topLevelVars = [];
190
- for (const route of topLevel)topLevelVars.push(await buildRoute({
191
- parentVar: 'rootRoute',
192
- route
193
- }));
194
- const rootOpts = [];
195
- const rootComponentName = await getImportNameForComponent(rootExtras?._component);
196
- if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
197
- if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
198
- if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
199
- if (rootLoaderDepsName) rootOpts.push(`loaderDeps: ${rootLoaderDepsName},`);
167
+ for (const route of topLevel)topLevelVars.push(await buildRoute(route, 'rootRoute'));
168
+ const rootOpts = rootModern ? await createRouteOptions(rootModern, false) : [];
200
169
  const routerGenTs = `// This file is auto-generated by Modern.js. Do not edit manually.
201
170
 
202
171
  import {
@@ -213,11 +182,7 @@ ${imports.join('\n')}
213
182
 
214
183
  export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
215
184
  ${rootOpts.join('\n ')}
216
- ${(0, external_shared_js_namespaceObject.createRouteStaticDataSnippet)({
217
- modernRouteId: rootExtras?.id,
218
- loaderName: rootLoaderName,
219
- actionName: rootActionName
220
- }) || ''}
185
+
221
186
  });
222
187
 
223
188
  ${statements.join('\n\n')}
@@ -30,7 +30,6 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  applyRouterRuntimeState: ()=>router_state_namespaceObject.applyRouterRuntimeState,
32
32
  applyRouterServerPrepareResult: ()=>router_state_namespaceObject.applyRouterServerPrepareResult,
33
- createRouterRuntimeState: ()=>router_state_namespaceObject.createRouterRuntimeState,
34
33
  createRouterServerSnapshot: ()=>router_state_namespaceObject.createRouterServerSnapshot,
35
34
  getRouterRuntimeState: ()=>router_state_namespaceObject.getRouterRuntimeState,
36
35
  getRouterServerSnapshot: ()=>router_state_namespaceObject.getRouterServerSnapshot
@@ -38,14 +37,12 @@ __webpack_require__.d(__webpack_exports__, {
38
37
  const router_state_namespaceObject = require("@modern-js/runtime-extensions/router-state");
39
38
  exports.applyRouterRuntimeState = __webpack_exports__.applyRouterRuntimeState;
40
39
  exports.applyRouterServerPrepareResult = __webpack_exports__.applyRouterServerPrepareResult;
41
- exports.createRouterRuntimeState = __webpack_exports__.createRouterRuntimeState;
42
40
  exports.createRouterServerSnapshot = __webpack_exports__.createRouterServerSnapshot;
43
41
  exports.getRouterRuntimeState = __webpack_exports__.getRouterRuntimeState;
44
42
  exports.getRouterServerSnapshot = __webpack_exports__.getRouterServerSnapshot;
45
43
  for(var __rspack_i in __webpack_exports__)if (-1 === [
46
44
  "applyRouterRuntimeState",
47
45
  "applyRouterServerPrepareResult",
48
- "createRouterRuntimeState",
49
46
  "createRouterServerSnapshot",
50
47
  "getRouterRuntimeState",
51
48
  "getRouterServerSnapshot"
@@ -30,6 +30,7 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  createRouteStaticData: ()=>routeStaticData_js_namespaceObject.createRouteStaticData,
32
32
  getLoaderHref: ()=>getLoaderHref,
33
+ getLoaderSignal: ()=>getLoaderSignal,
33
34
  handleModernLoaderError: ()=>handleModernLoaderError,
34
35
  handleModernLoaderResult: ()=>handleModernLoaderResult,
35
36
  isAbsoluteUrl: ()=>isAbsoluteUrl_js_namespaceObject.isAbsoluteUrl,
@@ -79,10 +80,13 @@ function mapSplatParamsForModernLoader(params, hasSplat) {
79
80
  return rest;
80
81
  }
81
82
  function getLoaderSignal(ctx) {
82
- const abortSignal = ctx?.abortController?.signal;
83
- if (abortSignal instanceof AbortSignal) return abortSignal;
84
- if (ctx?.signal instanceof AbortSignal) return ctx.signal;
85
- return new AbortController().signal;
83
+ const matchSignal = ctx?.abortController?.signal ?? ctx?.signal;
84
+ const requestSignal = ctx?.context?.request?.signal;
85
+ const signals = [
86
+ matchSignal,
87
+ requestSignal
88
+ ].filter((signal)=>signal instanceof AbortSignal);
89
+ return AbortSignal.any(signals);
86
90
  }
87
91
  function getLoaderHref(ctx) {
88
92
  if ('string' == typeof ctx?.location) return ctx.location;
@@ -145,6 +149,7 @@ function modernLoaderToTanstack(opts, modernLoader) {
145
149
  }
146
150
  exports.createRouteStaticData = __webpack_exports__.createRouteStaticData;
147
151
  exports.getLoaderHref = __webpack_exports__.getLoaderHref;
152
+ exports.getLoaderSignal = __webpack_exports__.getLoaderSignal;
148
153
  exports.handleModernLoaderError = __webpack_exports__.handleModernLoaderError;
149
154
  exports.handleModernLoaderResult = __webpack_exports__.handleModernLoaderResult;
150
155
  exports.isAbsoluteUrl = __webpack_exports__.isAbsoluteUrl;
@@ -157,6 +162,7 @@ exports.throwTanstackRedirect = __webpack_exports__.throwTanstackRedirect;
157
162
  for(var __rspack_i in __webpack_exports__)if (-1 === [
158
163
  "createRouteStaticData",
159
164
  "getLoaderHref",
165
+ "getLoaderSignal",
160
166
  "handleModernLoaderError",
161
167
  "handleModernLoaderResult",
162
168
  "isAbsoluteUrl",
@@ -0,0 +1,102 @@
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
+ createTanstackNavigation: ()=>createTanstackNavigation
32
+ });
33
+ const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
34
+ function createTanstackNavigation(router) {
35
+ let location;
36
+ let matches;
37
+ let snapshot;
38
+ return {
39
+ Link: external_prefetchLink_js_namespaceObject.Link,
40
+ getSnapshot () {
41
+ const state = router.state;
42
+ if (location !== state.location || void 0 === matches || matches.length !== state.matches.length || matches.some((match, index)=>match.params !== state.matches[index]?.params)) {
43
+ location = state.location;
44
+ matches = state.matches;
45
+ snapshot = {
46
+ location: {
47
+ pathname: location.pathname,
48
+ search: location.searchStr,
49
+ hash: '' !== location.hash ? `#${location.hash.replace(/^#/, '')}` : ''
50
+ },
51
+ params: Object.assign({}, ...matches.map((match)=>match.params))
52
+ };
53
+ }
54
+ return snapshot;
55
+ },
56
+ subscribe (listener) {
57
+ const stops = [
58
+ 'onBeforeNavigate',
59
+ 'onBeforeLoad',
60
+ 'onLoad',
61
+ 'onResolved'
62
+ ].map((event)=>router.subscribe(event, listener));
63
+ return ()=>{
64
+ for (const stop of stops)stop();
65
+ };
66
+ },
67
+ navigate (href, options) {
68
+ return router.navigate({
69
+ to: href,
70
+ replace: options?.replace,
71
+ ...options?.state === void 0 ? {} : {
72
+ state: options.state
73
+ }
74
+ });
75
+ },
76
+ createLinkProps (target) {
77
+ const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
78
+ return {
79
+ to: target.pathname,
80
+ ...void 0 !== target.search ? {
81
+ search: target.search
82
+ } : {},
83
+ ...void 0 !== target.hash && '' !== target.hash ? {
84
+ hash: target.hash
85
+ } : {},
86
+ ...void 0 === target.hashScrollIntoView ? {} : {
87
+ hashScrollIntoView: target.hashScrollIntoView
88
+ },
89
+ ...void 0 === preload ? {} : {
90
+ preload
91
+ }
92
+ };
93
+ }
94
+ };
95
+ }
96
+ exports.createTanstackNavigation = __webpack_exports__.createTanstackNavigation;
97
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
98
+ "createTanstackNavigation"
99
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
100
+ Object.defineProperty(exports, '__esModule', {
101
+ value: true
102
+ });
@@ -43,6 +43,7 @@ const external_clientHydration_js_namespaceObject = require("./clientHydration.j
43
43
  const external_hooks_js_namespaceObject = require("./hooks.js");
44
44
  const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
45
45
  const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
46
+ const external_navigation_js_namespaceObject = require("./navigation.js");
46
47
  const external_pluginShared_js_namespaceObject = require("./pluginShared.js");
47
48
  const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
48
49
  const external_routeHooks_js_namespaceObject = require("./routeHooks.js");
@@ -175,10 +176,14 @@ const tanstackRouterPlugin = (userConfig = {})=>{
175
176
  runtimeContext
176
177
  ]);
177
178
  if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {}) : null;
179
+ const navigation = (0, external_react_namespaceObject.useMemo)(()=>(0, external_navigation_js_namespaceObject.createTanstackNavigation)(router), [
180
+ router
181
+ ]);
178
182
  const runtimeState = (0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
179
183
  framework: 'tanstack',
180
184
  basename: _basename,
181
- instance: router
185
+ instance: router,
186
+ navigation
182
187
  });
183
188
  const lifecycleContext = {
184
189
  framework: 'tanstack',
@@ -42,6 +42,7 @@ const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.j
42
42
  const external_hooks_js_namespaceObject = require("./hooks.js");
43
43
  const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
44
44
  const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
45
+ const external_navigation_js_namespaceObject = require("./navigation.js");
45
46
  const external_pluginShared_js_namespaceObject = require("./pluginShared.js");
46
47
  const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
47
48
  const index_js_namespaceObject = require("./routeTree/index.js");
@@ -120,76 +121,93 @@ const tanstackRouterPlugin = (userConfig = {})=>{
120
121
  });
121
122
  const serverRouter = tanstackRouter;
122
123
  if (enableRsc) (0, payloadStorage_js_namespaceObject.setTanstackRscRouter)(serverRouter);
123
- await (0, external_ssrManagedTags_js_namespaceObject.attachServerSsrUtils)(serverRouter);
124
- const end = (0, time_namespaceObject.time)();
125
- try {
126
- await tanstackRouter.load({
127
- sync: true
128
- });
129
- } finally{
130
- const cost = end();
131
- context.ssrContext?.onTiming?.(constants_namespaceObject.LOADER_REPORTER_NAME, cost);
132
- }
133
- const serverLoadResult = serverRouter._serverResult;
134
- if (!serverLoadResult) {
135
- try {
136
- serverRouter.serverSsr?.cleanup?.();
137
- } catch {}
138
- throw new Error('TanStack Router completed an SSR load without a server result.');
139
- }
140
- if ('redirect' === serverLoadResult.type) {
141
- const { redirect } = serverLoadResult;
142
- try {
143
- serverRouter.serverSsr?.cleanup?.();
144
- } catch {}
145
- return interrupt(isRSCNavigation ? (0, payloadRouter_js_namespaceObject.handleTanstackRscRedirect)(redirect.headers, _basename, redirect.status) : redirect);
146
- }
147
- const routerErrors = (0, external_ssrManagedTags_js_namespaceObject.collectRouterErrors)(tanstackRouter);
148
- if (routerErrors && 'clientRender' === loaderFailureMode) {
149
- context.ssrContext?.response?.status(200);
150
- try {
151
- serverRouter.serverSsr?.cleanup?.();
152
- } catch {}
153
- throw Object.values(routerErrors)[0];
154
- }
155
- await (0, external_ssrPreload_js_namespaceObject.preloadMatchedRouteComponents)(serverRouter);
156
- context.ssrContext?.response?.status(serverLoadResult.status);
157
- await serverRouter.serverSsr?.dehydrate?.();
158
- if (enableRsc) {
159
- if (isRSCNavigation) await (0, external_ssrManagedTags_js_namespaceObject.waitForRouterSerialization)(serverRouter);
160
- (0, payloadStorage_js_namespaceObject.setTanstackRscServerPayload)((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
161
- omitClientLoaderData: isRSCNavigation
162
- }));
163
- }
164
- const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
165
- const hydrationScripts = (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)(ssrScriptTags);
166
- const matchedRouteIds = (0, index_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
167
- const routerServerSnapshot = (0, external_lifecycle_js_namespaceObject.createRouterServerSnapshot)({
124
+ let disposed = false;
125
+ let prepared = false;
126
+ const onAbort = ()=>controller.abort(rawRequest.signal.reason);
127
+ const cleanup = ()=>{
128
+ if (disposed) return;
129
+ disposed = true;
130
+ rawRequest.signal.removeEventListener('abort', onAbort);
131
+ controller.abort();
132
+ serverRouter.serverSsr?.cleanup?.();
133
+ };
134
+ (0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(context, {
168
135
  framework: 'tanstack',
169
136
  basename: _basename,
170
- statusCode: serverLoadResult.status,
171
- errors: routerErrors,
172
- matchedRouteIds,
173
- hydrationScripts
137
+ instance: serverRouter,
138
+ cleanup
139
+ });
140
+ rawRequest.signal.addEventListener('abort', onAbort, {
141
+ once: true
174
142
  });
175
- const runtimeContext = (0, external_lifecycle_js_namespaceObject.applyRouterServerPrepareResult)(context, {
176
- snapshot: routerServerSnapshot,
177
- cleanup: ()=>serverRouter.serverSsr?.cleanup?.(),
178
- state: {
143
+ try {
144
+ rawRequest.signal.throwIfAborted();
145
+ await (0, external_ssrManagedTags_js_namespaceObject.attachServerSsrUtils)(serverRouter);
146
+ rawRequest.signal.throwIfAborted();
147
+ const end = (0, time_namespaceObject.time)();
148
+ try {
149
+ await tanstackRouter.load({
150
+ sync: true
151
+ });
152
+ } finally{
153
+ const cost = end();
154
+ context.ssrContext?.onTiming?.(constants_namespaceObject.LOADER_REPORTER_NAME, cost);
155
+ }
156
+ rawRequest.signal.throwIfAborted();
157
+ const serverLoadResult = serverRouter._serverResult;
158
+ if (!serverLoadResult) throw new Error('TanStack Router completed an SSR load without a server result.');
159
+ if ('redirect' === serverLoadResult.type) {
160
+ const { redirect } = serverLoadResult;
161
+ return interrupt(isRSCNavigation ? (0, payloadRouter_js_namespaceObject.handleTanstackRscRedirect)(redirect.headers, _basename, redirect.status) : redirect);
162
+ }
163
+ const routerErrors = (0, external_ssrManagedTags_js_namespaceObject.collectRouterErrors)(tanstackRouter);
164
+ if (routerErrors && 'clientRender' === loaderFailureMode) {
165
+ context.ssrContext?.response?.status(200);
166
+ throw Object.values(routerErrors)[0];
167
+ }
168
+ await (0, external_ssrPreload_js_namespaceObject.preloadMatchedRouteComponents)(serverRouter);
169
+ context.ssrContext?.response?.status(serverLoadResult.status);
170
+ await serverRouter.serverSsr?.dehydrate?.();
171
+ if (enableRsc) {
172
+ if (isRSCNavigation) await (0, external_ssrManagedTags_js_namespaceObject.waitForRouterSerialization)(serverRouter);
173
+ (0, payloadStorage_js_namespaceObject.setTanstackRscServerPayload)((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
174
+ omitClientLoaderData: isRSCNavigation
175
+ }));
176
+ }
177
+ const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
178
+ const hydrationScripts = (0, external_ssrManagedTags_js_namespaceObject.routerManagedTagsToHtml)(ssrScriptTags);
179
+ const matchedRouteIds = (0, index_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
180
+ const routerServerSnapshot = {
179
181
  framework: 'tanstack',
180
182
  basename: _basename,
181
- instance: serverRouter,
182
- hydrationScripts,
183
+ statusCode: serverLoadResult.status,
184
+ errors: routerErrors,
183
185
  matchedRouteIds,
184
- serverSnapshot: routerServerSnapshot
185
- }
186
- });
187
- hooks.onAfterCreateRouter.call({
188
- ...routerLifecycleContext,
189
- router: serverRouter,
190
- serverSnapshot: routerServerSnapshot,
191
- runtimeContext
192
- });
186
+ hydrationScripts
187
+ };
188
+ const runtimeContext = (0, external_lifecycle_js_namespaceObject.applyRouterServerPrepareResult)(context, {
189
+ snapshot: routerServerSnapshot,
190
+ cleanup,
191
+ state: {
192
+ framework: 'tanstack',
193
+ basename: _basename,
194
+ instance: serverRouter,
195
+ navigation: (0, external_navigation_js_namespaceObject.createTanstackNavigation)(tanstackRouter)
196
+ }
197
+ });
198
+ rawRequest.signal.throwIfAborted();
199
+ hooks.onAfterCreateRouter.call({
200
+ ...routerLifecycleContext,
201
+ router: serverRouter,
202
+ serverSnapshot: (0, external_lifecycle_js_namespaceObject.getRouterServerSnapshot)(runtimeContext),
203
+ runtimeContext
204
+ });
205
+ prepared = true;
206
+ } finally{
207
+ if (!prepared) try {
208
+ cleanup();
209
+ } catch {}
210
+ }
193
211
  });
194
212
  api.wrapRoot((App)=>{
195
213
  const getRouteApp = ()=>{