@@ -139,7 +139,6 @@ function handleMiddlewareError(error: unknown, routeId: string) {
139139
140140export function getSingleFetchDataStrategy (
141141 manifest : AssetsManifest ,
142- routeModules : RouteModules ,
143142 ssr : boolean ,
144143 basename : string | undefined ,
145144 getRouter : ( ) => DataRouter
@@ -152,12 +151,11 @@ export function getSingleFetchDataStrategy(
152151 return runMiddlewarePipeline (
153152 args ,
154153 false ,
155- ( ) => singleFetchActionStrategy ( request , matches , basename ) ,
154+ ( ) => singleFetchActionStrategy ( args , basename ) ,
156155 handleMiddlewareError
157156 ) as Promise < Record < string , DataStrategyResult > > ;
158157 }
159158
160- // TODO: Enable middleware for this flow
161159 if ( ! ssr ) {
162160 // If this is SPA mode, there won't be any loaders below root and we'll
163161 // disable single fetch. We have to keep the `dataStrategy` defined for
@@ -193,15 +191,15 @@ export function getSingleFetchDataStrategy(
193191 // the other end
194192 let foundRevalidatingServerLoader = matches . some (
195193 ( m ) =>
196- m . shouldLoad &&
194+ m . unstable_shouldCallHandler ( ) &&
197195 manifest . routes [ m . route . id ] ?. hasLoader &&
198196 ! manifest . routes [ m . route . id ] ?. hasClientLoader
199197 ) ;
200198 if ( ! foundRevalidatingServerLoader ) {
201199 return runMiddlewarePipeline (
202200 args ,
203201 false ,
204- ( ) => nonSsrStrategy ( manifest , request , matches , basename ) ,
202+ ( ) => nonSsrStrategy ( args , manifest , basename ) ,
205203 handleMiddlewareError
206204 ) as Promise < Record < string , DataStrategyResult > > ;
207205 }
@@ -223,12 +221,10 @@ export function getSingleFetchDataStrategy(
223221 false ,
224222 ( ) =>
225223 singleFetchLoaderNavigationStrategy (
224+ args ,
226225 manifest ,
227- routeModules ,
228226 ssr ,
229227 getRouter ( ) ,
230- request ,
231- matches ,
232228 basename
233229 ) ,
234230 handleMiddlewareError
@@ -239,11 +235,10 @@ export function getSingleFetchDataStrategy(
239235// Actions are simple since they're singular calls to the server for both
240236// navigations and fetchers)
241237async function singleFetchActionStrategy (
242- request : Request ,
243- matches : DataStrategyFunctionArgs [ "matches" ] ,
238+ { request, matches } : DataStrategyFunctionArgs ,
244239 basename : string | undefined
245240) {
246- let actionMatch = matches . find ( ( m ) => m . shouldLoad ) ;
241+ let actionMatch = matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
247242 invariant ( actionMatch , "No action match found" ) ;
248243 let actionStatus : number | undefined = undefined ;
249244 let result = await actionMatch . resolve ( async ( handler ) => {
@@ -276,12 +271,11 @@ async function singleFetchActionStrategy(
276271
277272// We want to opt-out of Single Fetch when we aren't in SSR mode
278273async function nonSsrStrategy (
274+ { request, matches } : DataStrategyFunctionArgs ,
279275 manifest : AssetsManifest ,
280- request : Request ,
281- matches : DataStrategyFunctionArgs [ "matches" ] ,
282276 basename : string | undefined
283277) {
284- let matchesToLoad = matches . filter ( ( m ) => m . shouldLoad ) ;
278+ let matchesToLoad = matches . filter ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
285279 let url = stripIndexParam ( singleFetchUrl ( request . url , basename ) ) ;
286280 let init = await createRequestInit ( request ) ;
287281 let results : Record < string , DataStrategyResult > = { } ;
@@ -308,12 +302,10 @@ async function nonSsrStrategy(
308302// Loaders are trickier since we only want to hit the server once, so we
309303// create a singular promise for all server-loader routes to latch onto.
310304async function singleFetchLoaderNavigationStrategy (
305+ { request, matches } : DataStrategyFunctionArgs ,
311306 manifest : AssetsManifest ,
312- routeModules : RouteModules ,
313307 ssr : boolean ,
314308 router : DataRouter ,
315- request : Request ,
316- matches : DataStrategyFunctionArgs [ "matches" ] ,
317309 basename : string | undefined
318310) {
319311 // Track which routes need a server load - in case we need to tack on a
@@ -348,32 +340,20 @@ async function singleFetchLoaderNavigationStrategy(
348340
349341 let manifestRoute = manifest . routes [ m . route . id ] ;
350342
351- // Note: If this logic changes for routes that should not participate
352- // in Single Fetch, make sure you update getLowestLoadingIndex above
353- // as well
354- if ( ! m . shouldLoad ) {
355- // If we're not yet initialized and this is the initial load, respect
356- // `shouldLoad` because we're only dealing with `clientLoader.hydrate`
357- // routes which will fall into the `clientLoader` section below.
358- if ( ! router . state . initialized ) {
359- return ;
360- }
361-
362- // Otherwise, we opt out if we currently have data and a
363- // `shouldRevalidate` function. This implies that the user opted out
364- // via `shouldRevalidate`
365- if (
366- m . route . id in router . state . loaderData &&
367- manifestRoute &&
368- m . route . shouldRevalidate
369- ) {
370- if ( manifestRoute . hasLoader ) {
371- // If we have a server loader, make sure we don't include it in the
372- // single fetch .data request
373- foundOptOutRoute = true ;
374- }
375- return ;
376- }
343+ let defaultShouldRevalidate =
344+ ! m . unstable_shouldRevalidateArgs ||
345+ m . unstable_shouldRevalidateArgs . actionStatus == null ||
346+ m . unstable_shouldRevalidateArgs . actionStatus < 400 ;
347+ let shouldCall = m . unstable_shouldCallHandler ( defaultShouldRevalidate ) ;
348+
349+ if ( ! shouldCall ) {
350+ // If this route opted out of revalidation, we don't want to include
351+ // it in the single fetch .data request
352+ foundOptOutRoute ||=
353+ m . unstable_shouldRevalidateArgs != null && // This is a revalidation,
354+ manifestRoute ?. hasLoader === true && // for a route with a server loader,
355+ m . route . shouldRevalidate != null ; // and a shouldRevalidate function
356+ return ;
377357 }
378358
379359 // When a route has a client loader, it opts out of the singular call and
@@ -469,7 +449,7 @@ async function singleFetchLoaderFetcherStrategy(
469449 matches : DataStrategyFunctionArgs [ "matches" ] ,
470450 basename : string | undefined
471451) {
472- let fetcherMatch = matches . find ( ( m ) => m . shouldLoad ) ;
452+ let fetcherMatch = matches . find ( ( m ) => m . unstable_shouldCallHandler ( ) ) ;
473453 invariant ( fetcherMatch , "No fetcher match found" ) ;
474454 let result = await fetcherMatch . resolve ( async ( handler ) => {
475455 let url = stripIndexParam ( singleFetchUrl ( request . url , basename ) ) ;
0 commit comments