@tanstack/react-router 0.0.1-beta.222 → 0.0.1-beta.223

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/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.222",
4
+ "version": "0.0.1-beta.223",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -42,7 +42,7 @@
42
42
  "@babel/runtime": "^7.16.7",
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
- "@tanstack/history": "0.0.1-beta.222"
45
+ "@tanstack/history": "0.0.1-beta.223"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "rollup --config rollup.config.js"
package/src/Matches.tsx CHANGED
@@ -2,14 +2,50 @@ import * as React from 'react'
2
2
  import invariant from 'tiny-invariant'
3
3
  import warning from 'tiny-warning'
4
4
  import { CatchBoundary, ErrorComponent } from './CatchBoundary'
5
- import { RouteMatch } from './RouterProvider'
6
5
  import { useRouter, useRouterState } from './RouterProvider'
7
6
  import { ResolveRelativePath, ToOptions } from './link'
8
7
  import { AnyRoute, ReactNode, rootRouteId } from './route'
9
- import { RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo'
8
+ import {
9
+ FullSearchSchema,
10
+ ParseRoute,
11
+ RouteById,
12
+ RouteByPath,
13
+ RouteIds,
14
+ RoutePaths,
15
+ } from './routeInfo'
10
16
  import { RegisteredRouter } from './router'
11
17
  import { NoInfer, StrictOrFrom } from './utils'
12
18
 
19
+ export interface RouteMatch<
20
+ TRouteTree extends AnyRoute = AnyRoute,
21
+ TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
22
+ > {
23
+ id: string
24
+ routeId: TRouteId
25
+ pathname: string
26
+ params: RouteById<TRouteTree, TRouteId>['types']['allParams']
27
+ status: 'pending' | 'success' | 'error'
28
+ isFetching: boolean
29
+ invalid: boolean
30
+ error: unknown
31
+ paramsError: unknown
32
+ searchError: unknown
33
+ updatedAt: number
34
+ loadPromise?: Promise<void>
35
+ loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
36
+ __resolveLoadPromise?: () => void
37
+ context: RouteById<TRouteTree, TRouteId>['types']['allContext']
38
+ routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
39
+ search: FullSearchSchema<TRouteTree> &
40
+ RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
41
+ fetchedAt: number
42
+ shouldReloadDeps: any
43
+ abortController: AbortController
44
+ cause: 'enter' | 'stay'
45
+ }
46
+
47
+ export type AnyRouteMatch = RouteMatch<any>
48
+
13
49
  export function Matches() {
14
50
  const { routesById, state } = useRouter()
15
51
  const { matches } = state
@@ -36,9 +36,7 @@ import {
36
36
  } from './route'
37
37
  import {
38
38
  FullSearchSchema,
39
- ParseRoute,
40
39
  RouteById,
41
- RouteIds,
42
40
  RoutePaths,
43
41
  RoutesById,
44
42
  RoutesByPath,
@@ -64,6 +62,7 @@ import {
64
62
  escapeJSON,
65
63
  } from './utils'
66
64
  import { MatchRouteOptions } from './Matches'
65
+ import { AnyRouteMatch, RouteMatch } from './Matches'
67
66
 
68
67
  export interface CommitLocationOptions {
69
68
  replace?: boolean
@@ -475,8 +474,12 @@ export function RouterProvider<
475
474
  // around between navigation actions that only change leaf routes.
476
475
  const existingMatch = getRouteMatch(state, matchId)
477
476
 
477
+ const cause = state.matches.find((d) => d.id === matchId)
478
+ ? 'stay'
479
+ : 'enter'
480
+
478
481
  if (existingMatch) {
479
- return { ...existingMatch }
482
+ return { ...existingMatch, cause }
480
483
  }
481
484
 
482
485
  // Create a fresh route match
@@ -504,6 +507,7 @@ export function RouterProvider<
504
507
  abortController: new AbortController(),
505
508
  shouldReloadDeps: undefined,
506
509
  fetchedAt: 0,
510
+ cause,
507
511
  }
508
512
 
509
513
  return routeMatch
@@ -922,6 +926,7 @@ export function RouterProvider<
922
926
  navigate: (opts) =>
923
927
  navigate({ ...opts, from: match.pathname } as any),
924
928
  buildLocation,
929
+ cause: match.cause,
925
930
  })) ?? ({} as any)
926
931
 
927
932
  const context = {
@@ -977,10 +982,6 @@ export function RouterProvider<
977
982
  if (match.isFetching) {
978
983
  loadPromise = getRouteMatch(state, match.id)?.loadPromise
979
984
  } else {
980
- const cause = state.matches.find((d) => d.id === match.id)
981
- ? 'stay'
982
- : 'enter'
983
-
984
985
  const loaderContext: LoaderFnContext = {
985
986
  params: match.params,
986
987
  search: match.search,
@@ -991,7 +992,7 @@ export function RouterProvider<
991
992
  location: state.location,
992
993
  navigate: (opts) =>
993
994
  navigate({ ...opts, from: match.pathname } as any),
994
- cause,
995
+ cause: match.cause,
995
996
  }
996
997
 
997
998
  // Default to reloading the route all the time
@@ -1002,9 +1003,9 @@ export function RouterProvider<
1002
1003
  ? route.options.shouldReload?.(loaderContext)
1003
1004
  : !!(route.options.shouldReload ?? true)
1004
1005
 
1005
- if (cause === 'enter') {
1006
+ if (match.cause === 'enter') {
1006
1007
  match.shouldReloadDeps = shouldReloadDeps
1007
- } else if (cause === 'stay') {
1008
+ } else if (match.cause === 'stay') {
1008
1009
  if (typeof shouldReloadDeps === 'object') {
1009
1010
  // compare the deps to see if they've changed
1010
1011
  shouldReload = !deepEqual(
@@ -1547,31 +1548,3 @@ export function useRouter<
1547
1548
  warning(value, 'useRouter must be used inside a <RouterProvider> component!')
1548
1549
  return value as any
1549
1550
  }
1550
- export interface RouteMatch<
1551
- TRouteTree extends AnyRoute = AnyRoute,
1552
- TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
1553
- > {
1554
- id: string
1555
- routeId: TRouteId
1556
- pathname: string
1557
- params: RouteById<TRouteTree, TRouteId>['types']['allParams']
1558
- status: 'pending' | 'success' | 'error'
1559
- isFetching: boolean
1560
- invalid: boolean
1561
- error: unknown
1562
- paramsError: unknown
1563
- searchError: unknown
1564
- updatedAt: number
1565
- loadPromise?: Promise<void>
1566
- loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
1567
- __resolveLoadPromise?: () => void
1568
- context: RouteById<TRouteTree, TRouteId>['types']['allContext']
1569
- routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
1570
- search: FullSearchSchema<TRouteTree> &
1571
- RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
1572
- fetchedAt: number
1573
- shouldReloadDeps: any
1574
- abortController: AbortController
1575
- }
1576
-
1577
- export type AnyRouteMatch = RouteMatch<any>
package/src/route.ts CHANGED
@@ -2,7 +2,7 @@ import { HistoryLocation } from '@tanstack/history'
2
2
  import * as React from 'react'
3
3
  import invariant from 'tiny-invariant'
4
4
  import { useLoaderData, useMatch } from './Matches'
5
- import { AnyRouteMatch } from './RouterProvider'
5
+ import { AnyRouteMatch } from './Matches'
6
6
  import { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
7
7
  import { ParsedLocation } from './location'
8
8
  import { joinPaths, trimPath } from './path'
@@ -178,6 +178,7 @@ type BeforeLoadFn<
178
178
  location: ParsedLocation
179
179
  navigate: NavigateFn<AnyRoute>
180
180
  buildLocation: BuildLocationFn<AnyRoute>
181
+ cause: 'enter' | 'stay'
181
182
  }) => Promise<TRouteContext> | TRouteContext | void
182
183
 
183
184
  export type UpdatableRouteOptions<
package/src/router.ts CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  PendingRouteComponent,
18
18
  RouteComponent,
19
19
  } from './route'
20
- import { RouteMatch } from './RouterProvider'
20
+ import { RouteMatch } from './Matches'
21
21
  import { ParsedLocation } from './location'
22
22
  import { LocationState } from './location'
23
23
  import { SearchSerializer, SearchParser } from './searchParams'
package/src/useSearch.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AnyRoute } from './route'
2
2
  import { RouteIds, RouteById } from './routeInfo'
3
3
  import { RegisteredRouter } from './router'
4
- import { RouteMatch } from './RouterProvider'
4
+ import { RouteMatch } from './Matches'
5
5
  import { useMatch } from './Matches'
6
6
  import { StrictOrFrom } from './utils'
7
7
 
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { useMatch } from './Matches'
3
- import { RouteMatch } from './RouterProvider'
3
+ import { RouteMatch } from './Matches'
4
4
  import { AnyRoute } from './route'
5
5
  import { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'
6
6
  import { RegisteredRouter } from './router'