@tanstack/react-router 1.83.1 → 1.84.0

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/react-router",
3
- "version": "1.83.1",
3
+ "version": "1.84.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -9,12 +9,13 @@ import type {
9
9
  RegisteredRouter,
10
10
  Router,
11
11
  RouterOptions,
12
+ ViewTransitionOptions,
12
13
  } from './router'
13
14
 
14
15
  export interface CommitLocationOptions {
15
16
  replace?: boolean
16
17
  resetScroll?: boolean
17
- viewTransition?: boolean
18
+ viewTransition?: boolean | ViewTransitionOptions
18
19
  /**
19
20
  * @deprecated All navigations use React transitions under the hood now
20
21
  **/
package/src/link.tsx CHANGED
@@ -28,7 +28,11 @@ import type {
28
28
  RouteToPath,
29
29
  TrailingSlashOptionByRouter,
30
30
  } from './routeInfo'
31
- import type { AnyRouter, RegisteredRouter } from './router'
31
+ import type {
32
+ AnyRouter,
33
+ RegisteredRouter,
34
+ ViewTransitionOptions,
35
+ } from './router'
32
36
  import type {
33
37
  Constrain,
34
38
  Expand,
@@ -212,7 +216,8 @@ export interface NavigateOptionProps {
212
216
  /** @deprecated All navigations now use startTransition under the hood */
213
217
  startTransition?: boolean
214
218
  // if set to `true`, the router will wrap the resulting navigation in a document.startViewTransition() call.
215
- viewTransition?: boolean
219
+ // if set to `ViewTransitionOptions`, the router will pass the `types` field to document.startViewTransition({update: fn, types: viewTransition.types}) call
220
+ viewTransition?: boolean | ViewTransitionOptions
216
221
  ignoreBlocker?: boolean
217
222
  }
218
223
 
package/src/router.ts CHANGED
@@ -299,7 +299,7 @@ export interface RouterOptions<
299
299
  *
300
300
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property)
301
301
  */
302
- defaultViewTransition?: boolean
302
+ defaultViewTransition?: boolean | ViewTransitionOptions
303
303
  /**
304
304
  * @default 'fuzzy'
305
305
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#notfoundmode-property)
@@ -544,6 +544,10 @@ export interface DehydratedRouter {
544
544
  manifest?: Manifest
545
545
  }
546
546
 
547
+ export interface ViewTransitionOptions {
548
+ types: Array<string>
549
+ }
550
+
547
551
  export type RouterConstructorOptions<
548
552
  TRouteTree extends AnyRoute,
549
553
  TTrailingSlashOption extends TrailingSlashOption,
@@ -689,7 +693,8 @@ export class Router<
689
693
  Math.random() * 10000000,
690
694
  )}`
691
695
  resetNextScroll = true
692
- shouldViewTransition?: boolean = undefined
696
+ shouldViewTransition?: boolean | ViewTransitionOptions = undefined
697
+ isViewTransitionTypesSupported?: boolean = undefined
693
698
  subscribers = new Set<RouterListener<RouterEvent>>()
694
699
  dehydratedData?: TDehydrated
695
700
  viewTransitionPromise?: ControlledPromise<true>
@@ -853,6 +858,16 @@ export class Router<
853
858
  },
854
859
  })
855
860
  }
861
+
862
+ if (
863
+ typeof window !== 'undefined' &&
864
+ 'CSS' in window &&
865
+ typeof window.CSS.supports === 'function'
866
+ ) {
867
+ this.isViewTransitionTypesSupported = window.CSS.supports(
868
+ 'selector(:active-view-transition-type(a)',
869
+ )
870
+ }
856
871
  }
857
872
 
858
873
  get state() {
@@ -1061,7 +1076,7 @@ export class Router<
1061
1076
  return this.routesById as Record<string, AnyRoute>
1062
1077
  }
1063
1078
 
1064
- /**
1079
+ /**
1065
1080
  @deprecated use the following signature instead
1066
1081
  ```ts
1067
1082
  matchRoutes (
@@ -2054,7 +2069,23 @@ export class Router<
2054
2069
  'startViewTransition' in document &&
2055
2070
  typeof document.startViewTransition === 'function'
2056
2071
  ) {
2057
- document.startViewTransition(fn)
2072
+ // lib.dom.ts doesn't support viewTransition types variant yet.
2073
+ // TODO: Fix this when dom types are updated
2074
+ let startViewTransitionParams: any
2075
+
2076
+ if (
2077
+ typeof shouldViewTransition === 'object' &&
2078
+ this.isViewTransitionTypesSupported
2079
+ ) {
2080
+ startViewTransitionParams = {
2081
+ update: fn,
2082
+ types: shouldViewTransition.types,
2083
+ }
2084
+ } else {
2085
+ startViewTransitionParams = fn
2086
+ }
2087
+
2088
+ document.startViewTransition(startViewTransitionParams)
2058
2089
  } else {
2059
2090
  fn()
2060
2091
  }