@tanstack/router-generator 1.163.3 → 1.163.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +1 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +11 -10
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/generator.cjs +5 -1
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/types.d.cts +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.js +1 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.js +11 -10
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/generator.js +5 -1
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/package.json +3 -3
- package/src/filesystem/physical/getRouteNodes.ts +5 -0
- package/src/filesystem/virtual/getRouteNodes.ts +7 -15
- package/src/generator.ts +10 -7
- package/src/types.ts +1 -1
|
@@ -132,6 +132,11 @@ export async function getRouteNodes(
|
|
|
132
132
|
node.originalRoutePath = `/${dir}${node.originalRoutePath}`
|
|
133
133
|
}
|
|
134
134
|
node.filePath = filePath
|
|
135
|
+
// Virtual subtree nodes (from __virtual.ts) are embedded in a
|
|
136
|
+
// physical directory tree. They should use path-based parent
|
|
137
|
+
// inference, not the explicit virtual parent tracking. Clear any
|
|
138
|
+
// _virtualParentRoutePath that was set at construction time.
|
|
139
|
+
delete node._virtualParentRoutePath
|
|
135
140
|
})
|
|
136
141
|
|
|
137
142
|
routeNodes.push(...virtualRouteNodes)
|
|
@@ -26,25 +26,12 @@ function ensureLeadingUnderScore(id: string) {
|
|
|
26
26
|
return `_${id}`
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function flattenTree(
|
|
30
|
-
node: RouteNode,
|
|
31
|
-
parentRoutePath?: string,
|
|
32
|
-
): Array<RouteNode> {
|
|
33
|
-
// Store the explicit parent's routePath for virtual routes.
|
|
34
|
-
// This prevents the generator from auto-nesting based on path matching (#5822).
|
|
35
|
-
//
|
|
36
|
-
// Skip when the parent is the synthetic virtual root (`/${rootPathId}`).
|
|
37
|
-
// Root-level nodes should use path-based inference to find their parent.
|
|
38
|
-
const isRootParent = parentRoutePath === `/${rootPathId}`
|
|
39
|
-
if (parentRoutePath !== undefined && !isRootParent) {
|
|
40
|
-
node._virtualParentRoutePath = parentRoutePath
|
|
41
|
-
}
|
|
42
|
-
|
|
29
|
+
function flattenTree(node: RouteNode): Array<RouteNode> {
|
|
43
30
|
const result = [node]
|
|
44
31
|
|
|
45
32
|
if (node.children) {
|
|
46
33
|
for (const child of node.children) {
|
|
47
|
-
result.push(...flattenTree(child
|
|
34
|
+
result.push(...flattenTree(child))
|
|
48
35
|
}
|
|
49
36
|
}
|
|
50
37
|
delete node.children
|
|
@@ -194,6 +181,7 @@ export async function getRouteNodesRecursive(
|
|
|
194
181
|
return { filePath, variableName, fullPath }
|
|
195
182
|
}
|
|
196
183
|
const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/')
|
|
184
|
+
const virtualParentRoutePath = parent?.routePath ?? `/${rootPathId}`
|
|
197
185
|
|
|
198
186
|
switch (node.type) {
|
|
199
187
|
case 'index': {
|
|
@@ -205,6 +193,7 @@ export async function getRouteNodesRecursive(
|
|
|
205
193
|
variableName,
|
|
206
194
|
routePath,
|
|
207
195
|
_fsRouteType: 'static',
|
|
196
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
208
197
|
} satisfies RouteNode
|
|
209
198
|
}
|
|
210
199
|
|
|
@@ -230,6 +219,7 @@ export async function getRouteNodesRecursive(
|
|
|
230
219
|
routePath,
|
|
231
220
|
originalRoutePath,
|
|
232
221
|
_fsRouteType: 'static',
|
|
222
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
233
223
|
}
|
|
234
224
|
} else {
|
|
235
225
|
routeNode = {
|
|
@@ -240,6 +230,7 @@ export async function getRouteNodesRecursive(
|
|
|
240
230
|
originalRoutePath,
|
|
241
231
|
isVirtual: true,
|
|
242
232
|
_fsRouteType: 'static',
|
|
233
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
243
234
|
}
|
|
244
235
|
}
|
|
245
236
|
|
|
@@ -288,6 +279,7 @@ export async function getRouteNodesRecursive(
|
|
|
288
279
|
routePath,
|
|
289
280
|
originalRoutePath,
|
|
290
281
|
_fsRouteType: 'pathless_layout',
|
|
282
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
291
283
|
}
|
|
292
284
|
|
|
293
285
|
if (node.children !== undefined) {
|
package/src/generator.ts
CHANGED
|
@@ -1470,17 +1470,20 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
|
|
|
1470
1470
|
|
|
1471
1471
|
// Virtual routes may have an explicit parent from virtual config.
|
|
1472
1472
|
// If we can find that exact parent, use it to prevent auto-nesting siblings
|
|
1473
|
-
// based on path prefix matching
|
|
1474
|
-
// it was a virtual file-less route that got filtered out), keep using the
|
|
1475
|
-
// path-based parent we already computed above.
|
|
1473
|
+
// based on path prefix matching (#5822, #5431).
|
|
1476
1474
|
if (node._virtualParentRoutePath !== undefined) {
|
|
1477
|
-
const explicitParent =
|
|
1478
|
-
|
|
1479
|
-
|
|
1475
|
+
const explicitParent = acc.routeNodesByPath.get(
|
|
1476
|
+
node._virtualParentRoutePath,
|
|
1477
|
+
)
|
|
1480
1478
|
if (explicitParent) {
|
|
1481
1479
|
parentRoute = explicitParent
|
|
1480
|
+
} else if (node._virtualParentRoutePath === `/${rootPathId}`) {
|
|
1481
|
+
// The explicit parent is the root route (handled separately).
|
|
1482
|
+
// Override path-based inference so this node stays at root level.
|
|
1483
|
+
parentRoute = null
|
|
1482
1484
|
}
|
|
1483
|
-
//
|
|
1485
|
+
// Otherwise the explicit parent was a virtual file-less route that got
|
|
1486
|
+
// filtered out. Fall back to the path-based parentRoute already computed.
|
|
1484
1487
|
}
|
|
1485
1488
|
|
|
1486
1489
|
if (parentRoute) node.parent = parentRoute
|
package/src/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type RouteNode = {
|
|
|
15
15
|
createFileRouteProps?: Set<string>
|
|
16
16
|
/**
|
|
17
17
|
* For virtual routes: the routePath of the explicit parent from virtual config.
|
|
18
|
-
* Used to prevent auto-nesting siblings based on path prefix matching (#5822).
|
|
18
|
+
* Used to prevent auto-nesting siblings based on path prefix matching (#5822, #5431).
|
|
19
19
|
* Falls back to path-based inference if the explicit parent is not found
|
|
20
20
|
* (e.g., when the parent is a virtual file-less route that gets filtered out).
|
|
21
21
|
*/
|