@@ -154,7 +154,7 @@ type GetRouteInfoFunction = (routeId: string) => {
154
154
} ;
155
155
156
156
type FetchAndDecodeFunction = (
157
- request : Request ,
157
+ args : DataStrategyFunctionArgs ,
158
158
basename : string | undefined ,
159
159
targetRoutes ?: string [ ]
160
160
) => Promise < { status : number ; data : DecodedSingleFetchResults } > ;
@@ -233,12 +233,7 @@ export function getSingleFetchDataStrategyImpl(
233
233
234
234
// Fetcher loads are singular calls to one loader
235
235
if ( fetcherKey ) {
236
- return singleFetchLoaderFetcherStrategy (
237
- request ,
238
- matches ,
239
- fetchAndDecode ,
240
- basename
241
- ) ;
236
+ return singleFetchLoaderFetcherStrategy ( args , fetchAndDecode , basename ) ;
242
237
}
243
238
244
239
// Navigational loads are more complex...
@@ -256,16 +251,16 @@ export function getSingleFetchDataStrategyImpl(
256
251
// Actions are simple since they're singular calls to the server for both
257
252
// navigations and fetchers)
258
253
async function singleFetchActionStrategy (
259
- { request , matches } : DataStrategyFunctionArgs ,
254
+ args : DataStrategyFunctionArgs ,
260
255
fetchAndDecode : FetchAndDecodeFunction ,
261
256
basename : string | undefined
262
257
) {
263
- let actionMatch = matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
258
+ let actionMatch = args . matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
264
259
invariant ( actionMatch , "No action match found" ) ;
265
260
let actionStatus : number | undefined = undefined ;
266
261
let result = await actionMatch . resolve ( async ( handler ) => {
267
262
let result = await handler ( async ( ) => {
268
- let { data, status } = await fetchAndDecode ( request , basename , [
263
+ let { data, status } = await fetchAndDecode ( args , basename , [
269
264
actionMatch ! . route . id ,
270
265
] ) ;
271
266
actionStatus = status ;
@@ -290,12 +285,14 @@ async function singleFetchActionStrategy(
290
285
291
286
// We want to opt-out of Single Fetch when we aren't in SSR mode
292
287
async function nonSsrStrategy (
293
- { request , matches } : DataStrategyFunctionArgs ,
288
+ args : DataStrategyFunctionArgs ,
294
289
getRouteInfo : GetRouteInfoFunction ,
295
290
fetchAndDecode : FetchAndDecodeFunction ,
296
291
basename : string | undefined
297
292
) {
298
- let matchesToLoad = matches . filter ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
293
+ let matchesToLoad = args . matches . filter ( ( m ) =>
294
+ m . unstable_shouldCallHandler ( )
295
+ ) ;
299
296
let results : Record < string , DataStrategyResult > = { } ;
300
297
await Promise . all (
301
298
matchesToLoad . map ( ( m ) =>
@@ -308,9 +305,7 @@ async function nonSsrStrategy(
308
305
let routeId = m . route . id ;
309
306
let result = hasClientLoader
310
307
? await handler ( async ( ) => {
311
- let { data } = await fetchAndDecode ( request , basename , [
312
- routeId ,
313
- ] ) ;
308
+ let { data } = await fetchAndDecode ( args , basename , [ routeId ] ) ;
314
309
return unwrapSingleFetchResult ( data , routeId ) ;
315
310
} )
316
311
: await handler ( ) ;
@@ -327,7 +322,7 @@ async function nonSsrStrategy(
327
322
// Loaders are trickier since we only want to hit the server once, so we
328
323
// create a singular promise for all server-loader routes to latch onto.
329
324
async function singleFetchLoaderNavigationStrategy (
330
- { request , matches } : DataStrategyFunctionArgs ,
325
+ args : DataStrategyFunctionArgs ,
331
326
router : DataRouter ,
332
327
getRouteInfo : GetRouteInfoFunction ,
333
328
fetchAndDecode : FetchAndDecodeFunction ,
@@ -341,7 +336,7 @@ async function singleFetchLoaderNavigationStrategy(
341
336
let foundOptOutRoute = false ;
342
337
343
338
// Deferreds per-route so we can be sure they've all loaded via `match.resolve()`
344
- let routeDfds = matches . map ( ( ) => createDeferred < void > ( ) ) ;
339
+ let routeDfds = args . matches . map ( ( ) => createDeferred < void > ( ) ) ;
345
340
346
341
// Deferred we'll use for the singleular call to the server
347
342
let singleFetchDfd = createDeferred < DecodedSingleFetchResults > ( ) ;
@@ -350,7 +345,7 @@ async function singleFetchLoaderNavigationStrategy(
350
345
let results : Record < string , DataStrategyResult > = { } ;
351
346
352
347
let resolvePromise = Promise . all (
353
- matches . map ( async ( m , i ) =>
348
+ args . matches . map ( async ( m , i ) =>
354
349
m . resolve ( async ( handler ) => {
355
350
routeDfds [ i ] . resolve ( ) ;
356
351
let routeId = m . route . id ;
@@ -380,7 +375,7 @@ async function singleFetchLoaderNavigationStrategy(
380
375
}
381
376
try {
382
377
let result = await handler ( async ( ) => {
383
- let { data } = await fetchAndDecode ( request , basename , [ routeId ] ) ;
378
+ let { data } = await fetchAndDecode ( args , basename , [ routeId ] ) ;
384
379
return unwrapSingleFetchResult ( data , routeId ) ;
385
380
} ) ;
386
381
@@ -433,7 +428,7 @@ async function singleFetchLoaderNavigationStrategy(
433
428
? [ ...routesParams . keys ( ) ]
434
429
: undefined ;
435
430
try {
436
- let data = await fetchAndDecode ( request , basename , targetRoutes ) ;
431
+ let data = await fetchAndDecode ( args , basename , targetRoutes ) ;
437
432
singleFetchDfd . resolve ( data . data ) ;
438
433
} catch ( e ) {
439
434
singleFetchDfd . reject ( e ) ;
@@ -447,17 +442,16 @@ async function singleFetchLoaderNavigationStrategy(
447
442
448
443
// Fetcher loader calls are much simpler than navigational loader calls
449
444
async function singleFetchLoaderFetcherStrategy (
450
- request : Request ,
451
- matches : DataStrategyFunctionArgs [ "matches" ] ,
445
+ args : DataStrategyFunctionArgs ,
452
446
fetchAndDecode : FetchAndDecodeFunction ,
453
447
basename : string | undefined
454
448
) {
455
- let fetcherMatch = matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
449
+ let fetcherMatch = args . matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
456
450
invariant ( fetcherMatch , "No fetcher match found" ) ;
457
451
let routeId = fetcherMatch . route . id ;
458
452
let result = await fetcherMatch . resolve ( async ( handler ) =>
459
453
handler ( async ( ) => {
460
- let { data } = await fetchAndDecode ( request , basename , [ routeId ] ) ;
454
+ let { data } = await fetchAndDecode ( args , basename , [ routeId ] ) ;
461
455
return unwrapSingleFetchResult ( data , routeId ) ;
462
456
} )
463
457
) ;
@@ -508,10 +502,11 @@ export function singleFetchUrl(
508
502
}
509
503
510
504
async function fetchAndDecodeViaTurboStream (
511
- request : Request ,
505
+ args : DataStrategyFunctionArgs ,
512
506
basename : string | undefined ,
513
507
targetRoutes ?: string [ ]
514
508
) : Promise < { status : number ; data : DecodedSingleFetchResults } > {
509
+ let { request } = args ;
515
510
let url = singleFetchUrl ( request . url , basename ) ;
516
511
if ( request . method === "GET" ) {
517
512
url = stripIndexParam ( url ) ;
0 commit comments