@tanstack/router-core 1.129.7 → 1.129.9

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.
@@ -8,6 +8,7 @@ import { setupScrollRestoration } from "./scroll-restoration.js";
8
8
  import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
9
9
  import { rootRouteId } from "./root.js";
10
10
  import { redirect, isRedirect } from "./redirect.js";
11
+ import { createLRUCache } from "./lru-cache.js";
11
12
  function defaultSerializeError(err) {
12
13
  if (err instanceof Error) {
13
14
  const obj = {
@@ -176,7 +177,8 @@ class RouterCore {
176
177
  base: from,
177
178
  to: cleanPath(path),
178
179
  trailingSlash: this.options.trailingSlash,
179
- caseSensitive: this.options.caseSensitive
180
+ caseSensitive: this.options.caseSensitive,
181
+ parseCache: this.parsePathnameCache
180
182
  });
181
183
  return resolvedPath;
182
184
  };
@@ -192,6 +194,7 @@ class RouterCore {
192
194
  }
193
195
  return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
194
196
  };
197
+ this.parsePathnameCache = createLRUCache(1e3);
195
198
  this.getMatchedRoutes = (pathname, routePathname) => {
196
199
  return getMatchedRoutes({
197
200
  pathname,
@@ -200,7 +203,8 @@ class RouterCore {
200
203
  caseSensitive: this.options.caseSensitive,
201
204
  routesByPath: this.routesByPath,
202
205
  routesById: this.routesById,
203
- flatRoutes: this.flatRoutes
206
+ flatRoutes: this.flatRoutes,
207
+ parseCache: this.parsePathnameCache
204
208
  });
205
209
  };
206
210
  this.cancelMatch = (id) => {
@@ -261,7 +265,8 @@ class RouterCore {
261
265
  };
262
266
  const interpolatedNextTo = interpolatePath({
263
267
  path: nextTo,
264
- params: nextParams ?? {}
268
+ params: nextParams ?? {},
269
+ parseCache: this.parsePathnameCache
265
270
  }).interpolatedPath;
266
271
  const destRoutes = this.matchRoutes(
267
272
  interpolatedNextTo,
@@ -285,7 +290,8 @@ class RouterCore {
285
290
  params: nextParams ?? {},
286
291
  leaveWildcards: false,
287
292
  leaveParams: opts.leaveParams,
288
- decodeCharMap: this.pathParamsDecodeCharMap
293
+ decodeCharMap: this.pathParamsDecodeCharMap,
294
+ parseCache: this.parsePathnameCache
289
295
  }).interpolatedPath;
290
296
  let nextSearch = fromSearch;
291
297
  if (opts._includeValidateSearch && ((_a = this.options.search) == null ? void 0 : _a.strict)) {
@@ -335,11 +341,16 @@ class RouterCore {
335
341
  if (!maskedNext) {
336
342
  let params = {};
337
343
  const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
338
- const match = matchPathname(this.basepath, next.pathname, {
339
- to: d.from,
340
- caseSensitive: false,
341
- fuzzy: false
342
- });
344
+ const match = matchPathname(
345
+ this.basepath,
346
+ next.pathname,
347
+ {
348
+ to: d.from,
349
+ caseSensitive: false,
350
+ fuzzy: false
351
+ },
352
+ this.parsePathnameCache
353
+ );
343
354
  if (match) {
344
355
  params = match;
345
356
  return true;
@@ -1369,10 +1380,15 @@ class RouterCore {
1369
1380
  }
1370
1381
  const pending = (opts == null ? void 0 : opts.pending) === void 0 ? !this.state.isLoading : opts.pending;
1371
1382
  const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
1372
- const match = matchPathname(this.basepath, baseLocation.pathname, {
1373
- ...opts,
1374
- to: next.pathname
1375
- });
1383
+ const match = matchPathname(
1384
+ this.basepath,
1385
+ baseLocation.pathname,
1386
+ {
1387
+ ...opts,
1388
+ to: next.pathname
1389
+ },
1390
+ this.parsePathnameCache
1391
+ );
1376
1392
  if (!match) {
1377
1393
  return false;
1378
1394
  }
@@ -1551,7 +1567,8 @@ class RouterCore {
1551
1567
  path: route.id,
1552
1568
  params: routeParams,
1553
1569
  leaveWildcards: true,
1554
- decodeCharMap: this.pathParamsDecodeCharMap
1570
+ decodeCharMap: this.pathParamsDecodeCharMap,
1571
+ parseCache: this.parsePathnameCache
1555
1572
  }).interpolatedPath + loaderDepsHash;
1556
1573
  const existingMatch = this.getMatch(matchId);
1557
1574
  const previousMatch = this.state.matches.find(
@@ -1840,18 +1857,24 @@ function getMatchedRoutes({
1840
1857
  caseSensitive,
1841
1858
  routesByPath,
1842
1859
  routesById,
1843
- flatRoutes
1860
+ flatRoutes,
1861
+ parseCache
1844
1862
  }) {
1845
1863
  let routeParams = {};
1846
1864
  const trimmedPath = trimPathRight(pathname);
1847
1865
  const getMatchedParams = (route) => {
1848
1866
  var _a;
1849
- const result = matchPathname(basepath, trimmedPath, {
1850
- to: route.fullPath,
1851
- caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
1852
- // we need fuzzy matching for `notFoundMode: 'fuzzy'`
1853
- fuzzy: true
1854
- });
1867
+ const result = matchPathname(
1868
+ basepath,
1869
+ trimmedPath,
1870
+ {
1871
+ to: route.fullPath,
1872
+ caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
1873
+ // we need fuzzy matching for `notFoundMode: 'fuzzy'`
1874
+ fuzzy: true
1875
+ },
1876
+ parseCache
1877
+ );
1855
1878
  return result;
1856
1879
  };
1857
1880
  let foundRoute = routePathname !== void 0 ? routesByPath[routePathname] : void 0;