@tanstack/router-core 1.159.4 → 1.159.9

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/router-core",
3
- "version": "1.159.4",
3
+ "version": "1.159.9",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -74,7 +74,11 @@ const buildMatchContext = (
74
74
  return context
75
75
  }
76
76
 
77
- const _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {
77
+ const _handleNotFound = (
78
+ inner: InnerLoadContext,
79
+ err: NotFoundError,
80
+ routerCode?: string,
81
+ ) => {
78
82
  // Find the route that should handle the not found error
79
83
  // First check if a specific route is requested to show the error
80
84
  const routeCursor =
@@ -90,11 +94,19 @@ const _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {
90
94
  ).defaultNotFoundComponent
91
95
  }
92
96
 
93
- // Ensure we have a notFoundComponent
94
- invariant(
95
- routeCursor.options.notFoundComponent,
96
- 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',
97
- )
97
+ // For BEFORE_LOAD errors that will walk up to a parent route,
98
+ // don't require notFoundComponent on the current (child) route —
99
+ // an ancestor will handle it. Only enforce the invariant when
100
+ // we've reached a route that won't walk up further.
101
+ const willWalkUp = routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute
102
+
103
+ if (!willWalkUp) {
104
+ // Ensure we have a notFoundComponent
105
+ invariant(
106
+ routeCursor.options.notFoundComponent,
107
+ 'No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router.',
108
+ )
109
+ }
98
110
 
99
111
  // Find the match for this route
100
112
  const matchForRoute = inner.matches.find((m) => m.routeId === routeCursor.id)
@@ -109,9 +121,9 @@ const _handleNotFound = (inner: InnerLoadContext, err: NotFoundError) => {
109
121
  isFetching: false,
110
122
  }))
111
123
 
112
- if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) {
113
- err.routeId = routeCursor.parentRoute.id
114
- _handleNotFound(inner, err)
124
+ if (willWalkUp) {
125
+ err.routeId = routeCursor.parentRoute!.id
126
+ _handleNotFound(inner, err, routerCode)
115
127
  }
116
128
  }
117
129
 
@@ -119,6 +131,7 @@ const handleRedirectAndNotFound = (
119
131
  inner: InnerLoadContext,
120
132
  match: AnyRouteMatch | undefined,
121
133
  err: unknown,
134
+ routerCode?: string,
122
135
  ): void => {
123
136
  if (!isRedirect(err) && !isNotFound(err)) return
124
137
 
@@ -159,7 +172,7 @@ const handleRedirectAndNotFound = (
159
172
  err = inner.router.resolveRedirect(err)
160
173
  throw err
161
174
  } else {
162
- _handleNotFound(inner, err)
175
+ _handleNotFound(inner, err, routerCode)
163
176
  throw err
164
177
  }
165
178
  }
@@ -199,13 +212,23 @@ const handleSerialError = (
199
212
 
200
213
  err.routerCode = routerCode
201
214
  inner.firstBadMatchIndex ??= index
202
- handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)
215
+ handleRedirectAndNotFound(
216
+ inner,
217
+ inner.router.getMatch(matchId),
218
+ err,
219
+ routerCode,
220
+ )
203
221
 
204
222
  try {
205
223
  route.options.onError?.(err)
206
224
  } catch (errorHandlerErr) {
207
225
  err = errorHandlerErr
208
- handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)
226
+ handleRedirectAndNotFound(
227
+ inner,
228
+ inner.router.getMatch(matchId),
229
+ err,
230
+ routerCode,
231
+ )
209
232
  }
210
233
 
211
234
  inner.updateMatch(matchId, (prev) => {
package/src/router.ts CHANGED
@@ -1070,6 +1070,7 @@ export class RouterCore<
1070
1070
  let processRouteTreeResult: ProcessRouteTreeResult<TRouteTree>
1071
1071
  if (
1072
1072
  (isServer ?? this.isServer) &&
1073
+ process.env.NODE_ENV !== 'development' &&
1073
1074
  globalThis.__TSR_CACHE__ &&
1074
1075
  globalThis.__TSR_CACHE__.routeTree === this.routeTree
1075
1076
  ) {
@@ -1082,6 +1083,7 @@ export class RouterCore<
1082
1083
  // only cache if nothing else is cached yet
1083
1084
  if (
1084
1085
  (isServer ?? this.isServer) &&
1086
+ process.env.NODE_ENV !== 'development' &&
1085
1087
  globalThis.__TSR_CACHE__ === undefined
1086
1088
  ) {
1087
1089
  globalThis.__TSR_CACHE__ = {