@tanstack/router-core 1.134.13 → 1.134.18

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/src/router.ts CHANGED
@@ -896,6 +896,7 @@ export class RouterCore<
896
896
  rewrite?: LocationRewrite
897
897
  origin?: string
898
898
  latestLocation!: ParsedLocation<FullSearchSchema<TRouteTree>>
899
+ pendingBuiltLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>
899
900
  basepath!: string
900
901
  routeTree!: TRouteTree
901
902
  routesById!: RoutesById<TRouteTree>
@@ -1563,7 +1564,18 @@ export class RouterCore<
1563
1564
  }
1564
1565
 
1565
1566
  cancelMatches = () => {
1566
- this.state.pendingMatches?.forEach((match) => {
1567
+ const currentPendingMatches = this.state.matches.filter(
1568
+ (match) => match.status === 'pending',
1569
+ )
1570
+ const currentLoadingMatches = this.state.matches.filter(
1571
+ (match) => match.isFetching === 'loader',
1572
+ )
1573
+ const matchesToCancelArray = new Set([
1574
+ ...(this.state.pendingMatches ?? []),
1575
+ ...currentPendingMatches,
1576
+ ...currentLoadingMatches,
1577
+ ])
1578
+ matchesToCancelArray.forEach((match) => {
1567
1579
  this.cancelMatch(match.id)
1568
1580
  })
1569
1581
  }
@@ -1582,7 +1594,8 @@ export class RouterCore<
1582
1594
  } = {},
1583
1595
  ): ParsedLocation => {
1584
1596
  // We allow the caller to override the current location
1585
- const currentLocation = dest._fromLocation || this.latestLocation
1597
+ const currentLocation =
1598
+ dest._fromLocation || this.pendingBuiltLocation || this.latestLocation
1586
1599
 
1587
1600
  const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
1588
1601
  _buildLocation: true,
@@ -1945,7 +1958,11 @@ export class RouterCore<
1945
1958
  _includeValidateSearch: true,
1946
1959
  })
1947
1960
 
1948
- return this.commitLocation({
1961
+ this.pendingBuiltLocation = location as ParsedLocation<
1962
+ FullSearchSchema<TRouteTree>
1963
+ >
1964
+
1965
+ const commitPromise = this.commitLocation({
1949
1966
  ...location,
1950
1967
  viewTransition,
1951
1968
  replace,
@@ -1953,6 +1970,16 @@ export class RouterCore<
1953
1970
  hashScrollIntoView,
1954
1971
  ignoreBlocker,
1955
1972
  })
1973
+
1974
+ // Clear pending location after commit starts
1975
+ // We do this on next microtask to allow synchronous navigate calls to chain
1976
+ Promise.resolve().then(() => {
1977
+ if (this.pendingBuiltLocation === location) {
1978
+ this.pendingBuiltLocation = undefined
1979
+ }
1980
+ })
1981
+
1982
+ return commitPromise
1956
1983
  }
1957
1984
 
1958
1985
  /**