@tanstack/react-router 1.139.1 → 1.139.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.
@@ -3829,7 +3829,7 @@ export const Route = createFileRoute('/posts/$postId')({
3829
3829
 
3830
3830
  The not-found error above will be handled by the same route or nearest parent route that has either a \`notFoundComponent\` route option or the \`defaultNotFoundComponent\` router option configured.
3831
3831
 
3832
- If neither the route nor any suitable parent route is found to handle the error, the root route will handle it using TanStack Router's **extremely basic (and purposefully undesirable)** default not-found component that simply renders \`<div>Not Found</div>\`. It's highly recommended to either attach at least one \`notFoundComponent\` to the root route or configure a router-wide \`defaultNotFoundComponent\` to handle not-found errors.
3832
+ If neither the route nor any suitable parent route is found to handle the error, the root route will handle it using TanStack Router's **extremely basic (and purposefully undesirable)** default not-found component that simply renders \`<p>Not Found</p>\`. It's highly recommended to either attach at least one \`notFoundComponent\` to the root route or configure a router-wide \`defaultNotFoundComponent\` to handle not-found errors.
3833
3833
 
3834
3834
  > ⚠️ Throwing a notFound error in a beforeLoad method will always trigger the \_\_root notFoundComponent. Since beforeLoad methods are run prior to the route loader methods, there is no guarantee that any required data for layouts have successfully loaded before the error is thrown.
3835
3835
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.139.1",
3
+ "version": "1.139.5",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@
80
80
  "tiny-invariant": "^1.3.3",
81
81
  "tiny-warning": "^1.0.3",
82
82
  "@tanstack/history": "1.139.0",
83
- "@tanstack/router-core": "1.139.1"
83
+ "@tanstack/router-core": "1.139.5"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@testing-library/jest-dom": "^6.6.3",
@@ -108,20 +108,22 @@ export function Transitioner() {
108
108
  }, [isPagePending, previousIsPagePending, router])
109
109
 
110
110
  useLayoutEffect(() => {
111
- // The router was pending and now it's not
112
111
  if (previousIsAnyPending && !isAnyPending) {
112
+ const changeInfo = getLocationChangeInfo(router.state)
113
113
  router.emit({
114
114
  type: 'onResolved',
115
- ...getLocationChangeInfo(router.state),
115
+ ...changeInfo,
116
116
  })
117
117
 
118
- router.__store.setState((s) => ({
118
+ router.__store.setState((s: typeof router.state) => ({
119
119
  ...s,
120
120
  status: 'idle',
121
121
  resolvedLocation: s.location,
122
122
  }))
123
123
 
124
- handleHashScroll(router)
124
+ if (changeInfo.hrefChanged) {
125
+ handleHashScroll(router)
126
+ }
125
127
  }
126
128
  }, [isAnyPending, previousIsAnyPending, router])
127
129
 
@@ -3,6 +3,14 @@ import warning from 'tiny-warning'
3
3
  import { DefaultGlobalNotFound } from './not-found'
4
4
  import type { AnyRoute, AnyRouter } from '@tanstack/router-core'
5
5
 
6
+ /**
7
+ * Renders a not found component for a route when no matching route is found.
8
+ *
9
+ * @param router - The router instance containing the route configuration
10
+ * @param route - The route that triggered the not found state
11
+ * @param data - Additional data to pass to the not found component
12
+ * @returns The rendered not found component or a default fallback component
13
+ */
6
14
  export function renderRouteNotFound(
7
15
  router: AnyRouter,
8
16
  route: AnyRoute,
@@ -16,7 +24,7 @@ export function renderRouteNotFound(
16
24
  if (process.env.NODE_ENV === 'development') {
17
25
  warning(
18
26
  route.options.notFoundComponent,
19
- `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`,
27
+ `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,
20
28
  )
21
29
  }
22
30
 
@@ -179,20 +179,34 @@ export function useBlocker(
179
179
  const parsedLocation = router.parseLocation(location)
180
180
  const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)
181
181
  if (matchedRoutes.foundRoute === undefined) {
182
- throw new Error(`No route found for location ${location.href}`)
182
+ return {
183
+ routeId: '__notFound__',
184
+ fullPath: parsedLocation.pathname,
185
+ pathname: parsedLocation.pathname,
186
+ params: matchedRoutes.routeParams,
187
+ search: router.options.parseSearch(location.search),
188
+ }
183
189
  }
190
+
184
191
  return {
185
192
  routeId: matchedRoutes.foundRoute.id,
186
193
  fullPath: matchedRoutes.foundRoute.fullPath,
187
194
  pathname: parsedLocation.pathname,
188
195
  params: matchedRoutes.routeParams,
189
- search: parsedLocation.search,
196
+ search: router.options.parseSearch(location.search),
190
197
  }
191
198
  }
192
199
 
193
200
  const current = getLocation(blockerFnArgs.currentLocation)
194
201
  const next = getLocation(blockerFnArgs.nextLocation)
195
202
 
203
+ if (
204
+ current.routeId === '__notFound__' &&
205
+ next.routeId !== '__notFound__'
206
+ ) {
207
+ return false
208
+ }
209
+
196
210
  const shouldBlock = await shouldBlockFn({
197
211
  action: blockerFnArgs.action,
198
212
  current,