@tanstack/react-router 1.47.4 → 1.48.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/src/Match.tsx CHANGED
@@ -111,75 +111,27 @@ export const MatchInner = React.memo(function MatchInnerImpl({
111
111
  matchId: string
112
112
  }): any {
113
113
  const router = useRouter()
114
- const routeId = useRouterState({
115
- select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,
116
- })
117
-
118
- const route = router.routesById[routeId]!
119
-
120
- const matchIndex = useRouterState({
121
- select: (s) => {
122
- return s.matches.findIndex((d) => d.id === matchId)
123
- },
124
- })
125
114
 
126
- const match = useRouterState({
115
+ const { match, matchIndex, routeId } = useRouterState({
127
116
  select: (s) => {
117
+ const matchIndex = s.matches.findIndex((d) => d.id === matchId)
128
118
  const match = s.matches[matchIndex]!
129
- return pick(match, [
130
- 'id',
131
- 'status',
132
- 'error',
133
- 'loadPromise',
134
- 'minPendingPromise',
135
- ])
119
+ const routeId = match.routeId as string
120
+ return {
121
+ routeId,
122
+ matchIndex,
123
+ match: pick(match, ['id', 'status', 'error', 'loadPromise']),
124
+ }
136
125
  },
137
126
  })
138
127
 
128
+ const route = router.routesById[routeId]!
129
+
139
130
  const out = React.useMemo(() => {
140
131
  const Comp = route.options.component ?? router.options.defaultComponent
141
132
  return Comp ? <Comp key={routeId} /> : <Outlet />
142
133
  }, [routeId, route.options.component, router.options.defaultComponent])
143
134
 
144
- React.useEffect(() => {
145
- if (match.status === 'pending') {
146
- // We're pending, and if we have a minPendingMs, we need to wait for it
147
- const pendingMinMs =
148
- route.options.pendingMinMs ?? router.options.defaultPendingMinMs
149
-
150
- if (pendingMinMs && !match.minPendingPromise) {
151
- // Create a promise that will resolve after the minPendingMs
152
- if (!router.isServer) {
153
- const minPendingPromise = createControlledPromise<void>()
154
-
155
- router.updateMatch(match.id, (prev) => ({
156
- ...prev,
157
- minPendingPromise,
158
- }))
159
-
160
- const id = setTimeout(() => {
161
- minPendingPromise.resolve()
162
-
163
- // We've handled the minPendingPromise, so we can delete it
164
- router.updateMatch(match.id, (prev) => ({
165
- ...prev,
166
- minPendingPromise: undefined,
167
- }))
168
- }, pendingMinMs)
169
- return () => clearTimeout(id)
170
- }
171
- }
172
- }
173
- return undefined
174
- }, [
175
- match.id,
176
- match.loadPromise,
177
- match.minPendingPromise,
178
- match.status,
179
- route.options.pendingMinMs,
180
- router,
181
- ])
182
-
183
135
  // function useChangedDiff(value: any) {
184
136
  // const ref = React.useRef(value)
185
137
  // const changed = ref.current !== value
@@ -258,6 +210,33 @@ export const MatchInner = React.memo(function MatchInnerImpl({
258
210
  }
259
211
 
260
212
  if (match.status === 'pending') {
213
+ // We're pending, and if we have a minPendingMs, we need to wait for it
214
+ const pendingMinMs =
215
+ route.options.pendingMinMs ?? router.options.defaultPendingMinMs
216
+
217
+ if (pendingMinMs && !router.getMatch(match.id)?.minPendingPromise) {
218
+ // Create a promise that will resolve after the minPendingMs
219
+ if (!router.isServer) {
220
+ const minPendingPromise = createControlledPromise<void>()
221
+
222
+ Promise.resolve().then(() => {
223
+ router.updateMatch(match.id, (prev) => ({
224
+ ...prev,
225
+ minPendingPromise,
226
+ }))
227
+ })
228
+
229
+ setTimeout(() => {
230
+ minPendingPromise.resolve()
231
+
232
+ // We've handled the minPendingPromise, so we can delete it
233
+ router.updateMatch(match.id, (prev) => ({
234
+ ...prev,
235
+ minPendingPromise: undefined,
236
+ }))
237
+ }, pendingMinMs)
238
+ }
239
+ }
261
240
  throw match.loadPromise
262
241
  }
263
242
 
package/src/fileRoute.ts CHANGED
@@ -12,16 +12,14 @@ import type {
12
12
  AnyContext,
13
13
  AnyPathParams,
14
14
  AnyRoute,
15
- AnySearchSchema,
15
+ AnySearchValidator,
16
+ DefaultSearchValidator,
16
17
  FileBaseRouteOptions,
17
18
  InferAllContext,
18
19
  ResolveAllContext,
19
20
  ResolveAllParamsFromParent,
20
- ResolveFullSearchSchema,
21
- ResolveFullSearchSchemaInput,
22
21
  ResolveLoaderData,
23
22
  ResolveRouteContext,
24
- ResolveSearchSchemaUsed,
25
23
  Route,
26
24
  RouteConstraints,
27
25
  RouteContext,
@@ -75,17 +73,7 @@ export class FileRoute<
75
73
  }
76
74
 
77
75
  createRoute = <
78
- TSearchSchemaInput = Record<string, unknown>,
79
- TSearchSchema = {},
80
- TSearchSchemaUsed = ResolveSearchSchemaUsed<
81
- TSearchSchemaInput,
82
- TSearchSchema
83
- >,
84
- TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
85
- TParentRoute,
86
- TSearchSchemaUsed
87
- >,
88
- TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
76
+ TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
89
77
  TParams = Record<ParsePathParams<TPath>, string>,
90
78
  TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
91
79
  TRouteContextReturn = RouteContext,
@@ -97,10 +85,9 @@ export class FileRoute<
97
85
  TChildren = unknown,
98
86
  >(
99
87
  options?: FileBaseRouteOptions<
88
+ TParentRoute,
100
89
  TPath,
101
- TSearchSchemaInput,
102
- TSearchSchema,
103
- TFullSearchSchema,
90
+ TSearchValidator,
104
91
  TParams,
105
92
  TAllParams,
106
93
  TRouteContextReturn,
@@ -110,9 +97,10 @@ export class FileRoute<
110
97
  TLoaderDataReturn
111
98
  > &
112
99
  UpdatableRouteOptions<
100
+ TParentRoute,
113
101
  TId,
114
102
  TAllParams,
115
- TFullSearchSchema,
103
+ TSearchValidator,
116
104
  TLoaderData,
117
105
  TAllContext,
118
106
  TRouteContext,
@@ -124,11 +112,7 @@ export class FileRoute<
124
112
  TFullPath,
125
113
  TFilePath,
126
114
  TId,
127
- TSearchSchemaInput,
128
- TSearchSchema,
129
- TSearchSchemaUsed,
130
- TFullSearchSchemaInput,
131
- TFullSearchSchema,
115
+ TSearchValidator,
132
116
  TParams,
133
117
  TAllParams,
134
118
  TRouteContextReturn,
@@ -181,9 +165,10 @@ export function FileRouteLoader<
181
165
 
182
166
  export type LazyRouteOptions = Pick<
183
167
  UpdatableRouteOptions<
168
+ AnyRoute,
184
169
  string,
185
170
  AnyPathParams,
186
- AnySearchSchema,
171
+ AnySearchValidator,
187
172
  {},
188
173
  AnyContext,
189
174
  AnyContext,
package/src/index.tsx CHANGED
@@ -139,6 +139,7 @@ export {
139
139
  export type {
140
140
  AnyPathParams,
141
141
  SearchSchemaInput,
142
+ SearchValidatorAdapter,
142
143
  AnySearchSchema,
143
144
  AnyContext,
144
145
  RouteContext,
@@ -154,9 +155,6 @@ export type {
154
155
  MetaDescriptor,
155
156
  RouteLinkEntry,
156
157
  ParseParamsFn,
157
- SearchSchemaValidator,
158
- SearchSchemaValidatorObj,
159
- SearchSchemaValidatorFn,
160
158
  RouteLoaderFn,
161
159
  LoaderFnContext,
162
160
  SearchFilter,