@tanstack/router-core 0.0.1-alpha.4 → 0.0.1-alpha.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-alpha.4",
4
+ "version": "0.0.1-alpha.5",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
package/src/index.ts CHANGED
@@ -827,7 +827,8 @@ export interface RouterState {
827
827
  matches: RouteMatch[]
828
828
  lastUpdated: number
829
829
  loaderData: unknown
830
- action?: ActionState
830
+ currentAction?: ActionState
831
+ latestAction?: ActionState
831
832
  actions: Record<string, Action>
832
833
  pending?: PendingState
833
834
  }
@@ -948,7 +949,8 @@ export interface Action<
948
949
  // TError = unknown,
949
950
  > {
950
951
  submit: (submission?: TPayload) => Promise<TResponse>
951
- latest?: ActionState
952
+ current?: ActionState<TPayload, TResponse>
953
+ latest?: ActionState<TPayload, TResponse>
952
954
  pending: ActionState<TPayload, TResponse>[]
953
955
  }
954
956
 
@@ -1013,6 +1015,7 @@ export interface Router<
1013
1015
  routeTree: Route<TAllRouteInfo, RouteInfo>
1014
1016
  routesById: RoutesById<TAllRouteInfo>
1015
1017
  navigationPromise: Promise<void>
1018
+ removeActionQueue: { action: Action; actionState: ActionState }[]
1016
1019
  startedLoadingAt: number
1017
1020
  destroy: () => void
1018
1021
  resolveNavigation: () => void
@@ -1099,6 +1102,7 @@ export function createRouter<
1099
1102
  let router: Router<TRouteConfig, TAllRouteInfo> = {
1100
1103
  options: originalOptions,
1101
1104
  listeners: [],
1105
+ removeActionQueue: [],
1102
1106
  // Resolved after construction
1103
1107
  basepath: '',
1104
1108
  routeTree: undefined!,
@@ -1249,7 +1253,7 @@ export function createRouter<
1249
1253
 
1250
1254
  const toMatches = router.matchRoutes(pathname)
1251
1255
 
1252
- const prevParams = last(fromMatches)?.params
1256
+ const prevParams = { ...last(fromMatches)?.params }
1253
1257
 
1254
1258
  let nextParams =
1255
1259
  (dest.params ?? true) === true
@@ -1261,7 +1265,7 @@ export function createRouter<
1261
1265
  .map((d) => d.options.stringifyParams)
1262
1266
  .filter(Boolean)
1263
1267
  .forEach((fn) => {
1264
- Object.assign(nextParams!, fn!(nextParams!))
1268
+ Object.assign({}, nextParams!, fn!(nextParams!))
1265
1269
  })
1266
1270
  }
1267
1271
 
@@ -1406,10 +1410,23 @@ export function createRouter<
1406
1410
  router.startedLoadingAt = id
1407
1411
 
1408
1412
  if (next) {
1413
+ // If the location.href has changed
1414
+
1409
1415
  // Ingest the new location
1410
1416
  router.location = next
1411
1417
  }
1412
1418
 
1419
+ // Clear out old actions
1420
+ router.removeActionQueue.forEach(({ action, actionState }) => {
1421
+ if (router.state.currentAction === actionState) {
1422
+ router.state.currentAction = undefined
1423
+ }
1424
+ if (action.current === actionState) {
1425
+ action.current = undefined
1426
+ }
1427
+ })
1428
+ router.removeActionQueue = []
1429
+
1413
1430
  // Cancel any pending matches
1414
1431
  router.cancelMatches()
1415
1432
 
@@ -1418,14 +1435,6 @@ export function createRouter<
1418
1435
  strictParseParams: true,
1419
1436
  })
1420
1437
 
1421
- unloadedMatches.forEach((match, index) => {
1422
- const parent = unloadedMatches[index - 1]
1423
- const child = unloadedMatches[index + 1]
1424
-
1425
- if (parent) match.__.setParentMatch(parent)
1426
- if (child) match.__.addChildMatch(child)
1427
- })
1428
-
1429
1438
  router.state = {
1430
1439
  ...router.state,
1431
1440
  pending: {
@@ -1641,6 +1650,8 @@ export function createRouter<
1641
1650
 
1642
1651
  recurse([router.routeTree])
1643
1652
 
1653
+ cascadeLoaderData(matches)
1654
+
1644
1655
  return matches
1645
1656
  },
1646
1657
 
@@ -2011,12 +2022,14 @@ export function createRoute<
2011
2022
  submission,
2012
2023
  }
2013
2024
 
2025
+ action.current = actionState
2014
2026
  action.latest = actionState
2015
2027
  action.pending.push(actionState)
2016
2028
 
2017
2029
  router.state = {
2018
2030
  ...router.state,
2019
- action: actionState,
2031
+ currentAction: actionState,
2032
+ latestAction: actionState,
2020
2033
  }
2021
2034
 
2022
2035
  router.notify()
@@ -2036,9 +2049,7 @@ export function createRoute<
2036
2049
  actionState.status = 'error'
2037
2050
  } finally {
2038
2051
  action.pending = action.pending.filter((d) => d !== actionState)
2039
- if (actionState === router.state.action) {
2040
- router.state.action = undefined
2041
- }
2052
+ router.removeActionQueue.push({ action, actionState })
2042
2053
  router.notify()
2043
2054
  }
2044
2055
  },
@@ -2374,8 +2385,8 @@ export interface RouteMatch<
2374
2385
  }) => void)
2375
2386
  abortController: AbortController
2376
2387
  latestId: string
2377
- setParentMatch: (parentMatch: RouteMatch) => void
2378
- addChildMatch: (childMatch: RouteMatch) => void
2388
+ // setParentMatch: (parentMatch: RouteMatch) => void
2389
+ // addChildMatch: (childMatch: RouteMatch) => void
2379
2390
  validate: () => void
2380
2391
  startPending: () => void
2381
2392
  cancelPending: () => void
@@ -2450,18 +2461,18 @@ export function createRouteMatch<
2450
2461
  clearTimeout(routeMatch.__.pendingMinTimeout)
2451
2462
  delete routeMatch.__.pendingMinPromise
2452
2463
  },
2453
- setParentMatch: (parentMatch?: RouteMatch) => {
2454
- routeMatch.parentMatch = parentMatch
2455
- },
2456
- addChildMatch: (childMatch: RouteMatch) => {
2457
- if (
2458
- routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
2459
- ) {
2460
- return
2461
- }
2462
-
2463
- routeMatch.childMatches.push(childMatch)
2464
- },
2464
+ // setParentMatch: (parentMatch?: RouteMatch) => {
2465
+ // routeMatch.parentMatch = parentMatch
2466
+ // },
2467
+ // addChildMatch: (childMatch: RouteMatch) => {
2468
+ // if (
2469
+ // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
2470
+ // ) {
2471
+ // return
2472
+ // }
2473
+
2474
+ // routeMatch.childMatches.push(childMatch)
2475
+ // },
2465
2476
  validate: () => {
2466
2477
  // Validate the search params and stabilize them
2467
2478
  const parentSearch =
@@ -2590,7 +2601,6 @@ export function createRouteMatch<
2590
2601
  data,
2591
2602
  )
2592
2603
 
2593
- cascadeLoaderData(routeMatch)
2594
2604
  routeMatch.error = undefined
2595
2605
  routeMatch.status = 'success'
2596
2606
  routeMatch.updatedAt = Date.now()
@@ -2648,19 +2658,17 @@ export function createRouteMatch<
2648
2658
  return routeMatch
2649
2659
  }
2650
2660
 
2651
- function cascadeLoaderData(routeMatch: RouteMatch<any, any>) {
2652
- if (routeMatch.parentMatch) {
2653
- routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, {
2654
- ...routeMatch.parentMatch.loaderData,
2655
- ...routeMatch.routeLoaderData,
2656
- })
2657
- }
2661
+ function cascadeLoaderData(matches: RouteMatch<any, any>[]) {
2662
+ matches.forEach((match, index) => {
2663
+ const parent = matches[index - 1]
2658
2664
 
2659
- if (routeMatch.childMatches.length) {
2660
- routeMatch.childMatches.forEach((childMatch) => {
2661
- cascadeLoaderData(childMatch)
2662
- })
2663
- }
2665
+ if (parent) {
2666
+ match.loaderData = replaceEqualDeep(match.loaderData, {
2667
+ ...parent.loaderData,
2668
+ ...match.routeLoaderData,
2669
+ })
2670
+ }
2671
+ })
2664
2672
  }
2665
2673
 
2666
2674
  export function matchPathname(