@tanstack/react-router 1.64.2 → 1.64.3

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.64.2",
3
+ "version": "1.64.3",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -48,6 +48,7 @@ export type BuildLocationFn = <
48
48
  >(
49
49
  opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
50
50
  leaveParams?: boolean
51
+ _includeValidateSearch?: boolean
51
52
  },
52
53
  ) => ParsedLocation
53
54
 
package/src/link.tsx CHANGED
@@ -757,8 +757,9 @@ export function useLinkProps<
757
757
  })
758
758
 
759
759
  // All is well? Navigate!
760
- router.commitLocation({
761
- ...next,
760
+ // N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing
761
+ router.buildAndCommitLocation({
762
+ ...options,
762
763
  replace,
763
764
  resetScroll,
764
765
  startTransition,
package/src/router.ts CHANGED
@@ -1460,8 +1460,24 @@ export class Router<
1460
1460
  ? postSearchFilters.reduce((prev, next) => next(prev), destSearch)
1461
1461
  : destSearch
1462
1462
 
1463
- const search = replaceEqualDeep(fromSearch, postFilteredSearch)
1463
+ let search = postFilteredSearch
1464
1464
 
1465
+ if (opts._includeValidateSearch) {
1466
+ matchedRoutesResult?.matchedRoutes.forEach((route) => {
1467
+ try {
1468
+ if (route.options.validateSearch) {
1469
+ const validator =
1470
+ typeof route.options.validateSearch === 'object'
1471
+ ? route.options.validateSearch.parse
1472
+ : route.options.validateSearch
1473
+ search = { ...search, ...validator(search) }
1474
+ }
1475
+ } catch (e) {
1476
+ // ignore errors here because they are already handled in matchRoutes
1477
+ }
1478
+ })
1479
+ }
1480
+ search = replaceEqualDeep(fromSearch, search)
1465
1481
  const searchStr = this.options.stringifySearch(search)
1466
1482
 
1467
1483
  const hash =
@@ -1644,7 +1660,10 @@ export class Router<
1644
1660
  rest.hash = parsed.hash
1645
1661
  }
1646
1662
 
1647
- const location = this.buildLocation(rest as any)
1663
+ const location = this.buildLocation({
1664
+ ...(rest as any),
1665
+ _includeValidateSearch: true,
1666
+ })
1648
1667
  return this.commitLocation({
1649
1668
  ...location,
1650
1669
  viewTransition,