@tanstack/router-core 1.154.8 → 1.154.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.154.8",
3
+ "version": "1.154.12",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/router.ts CHANGED
@@ -1330,22 +1330,9 @@ export class RouterCore<
1330
1330
  }
1331
1331
  }
1332
1332
 
1333
- globalNotFoundRouteId = (() => {
1334
- if (!isGlobalNotFound) {
1335
- return undefined
1336
- }
1337
-
1338
- if (this.options.notFoundMode !== 'root') {
1339
- for (let i = matchedRoutes.length - 1; i >= 0; i--) {
1340
- const route = matchedRoutes[i]!
1341
- if (route.children) {
1342
- return route.id
1343
- }
1344
- }
1345
- }
1346
-
1347
- return rootRouteId
1348
- })()
1333
+ globalNotFoundRouteId = isGlobalNotFound
1334
+ ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes)
1335
+ : undefined
1349
1336
  }
1350
1337
 
1351
1338
  const matches: Array<AnyRouteMatch> = []
@@ -1775,16 +1762,30 @@ export class RouterCore<
1775
1762
  params: nextParams,
1776
1763
  }).interpolatedPath
1777
1764
 
1778
- const { matches: destMatches, rawParams } = this.matchRoutesInternal(
1779
- { pathname: interpolatedNextTo } as ParsedLocation,
1780
- { _buildLocation: true },
1781
- )
1782
- const destRoutes = destMatches.map(
1783
- (d) => this.looseRoutesById[d.routeId]!,
1784
- )
1785
-
1786
- // Check if any match indicates global not found
1787
- const globalNotFoundMatch = destMatches.find((m) => m.globalNotFound)
1765
+ // Use lightweight getMatchedRoutes instead of matchRoutesInternal
1766
+ // This avoids creating full match objects (AbortController, ControlledPromise, etc.)
1767
+ // which are expensive and not needed for buildLocation
1768
+ const destMatchResult = this.getMatchedRoutes(interpolatedNextTo)
1769
+ let destRoutes = destMatchResult.matchedRoutes
1770
+ const rawParams = destMatchResult.routeParams
1771
+
1772
+ // Compute globalNotFoundRouteId using the same logic as matchRoutesInternal
1773
+ const isGlobalNotFound = destMatchResult.foundRoute
1774
+ ? destMatchResult.foundRoute.path !== '/' &&
1775
+ destMatchResult.routeParams['**']
1776
+ : trimPathRight(interpolatedNextTo)
1777
+
1778
+ let globalNotFoundRouteId: string | undefined
1779
+ if (isGlobalNotFound) {
1780
+ if (this.options.notFoundRoute) {
1781
+ destRoutes = [...destRoutes, this.options.notFoundRoute]
1782
+ } else {
1783
+ globalNotFoundRouteId = findGlobalNotFoundRouteId(
1784
+ this.options.notFoundMode,
1785
+ destRoutes,
1786
+ )
1787
+ }
1788
+ }
1788
1789
 
1789
1790
  // If there are any params, we need to stringify them
1790
1791
  if (Object.keys(nextParams).length > 0) {
@@ -1877,7 +1878,7 @@ export class RouterCore<
1877
1878
  routes: destRoutes,
1878
1879
  params: snapshotParams,
1879
1880
  searchStr,
1880
- globalNotFoundRouteId: globalNotFoundMatch?.routeId,
1881
+ globalNotFoundRouteId,
1881
1882
  })
1882
1883
 
1883
1884
  // Create the full path of the location
@@ -3045,7 +3046,7 @@ function applySearchMiddleware({
3045
3046
  }: {
3046
3047
  search: any
3047
3048
  dest: BuildNextOptions
3048
- destRoutes: Array<AnyRoute>
3049
+ destRoutes: ReadonlyArray<AnyRoute>
3049
3050
  _includeValidateSearch: boolean | undefined
3050
3051
  }) {
3051
3052
  const allMiddlewares =
@@ -3151,3 +3152,18 @@ function applySearchMiddleware({
3151
3152
  // Start applying middlewares
3152
3153
  return applyNext(0, search)
3153
3154
  }
3155
+
3156
+ function findGlobalNotFoundRouteId(
3157
+ notFoundMode: 'root' | 'fuzzy' | undefined,
3158
+ routes: ReadonlyArray<AnyRoute>,
3159
+ ) {
3160
+ if (notFoundMode !== 'root') {
3161
+ for (let i = routes.length - 1; i >= 0; i--) {
3162
+ const route = routes[i]!
3163
+ if (route.children) {
3164
+ return route.id
3165
+ }
3166
+ }
3167
+ }
3168
+ return rootRouteId
3169
+ }