@@ -15,9 +15,11 @@ import {
1515 stripBasename ,
1616} from "../../router/utils" ;
1717import { createRequestInit } from "./data" ;
18- import type { EntryContext } from "./entry" ;
18+ import type { AssetsManifest , EntryContext } from "./entry" ;
1919import { escapeHtml } from "./markup" ;
2020import invariant from "./invariant" ;
21+ import type { RouteModules } from "./routeModules" ;
22+ import type { DataRouteMatch } from "../../context" ;
2123
2224export const SingleFetchRedirectSymbol = Symbol ( "SingleFetchRedirect" ) ;
2325
@@ -147,10 +149,10 @@ export function StreamTransfer({
147149 }
148150}
149151
150- type GetRouteInfoFunction = ( routeId : string ) => {
152+ type GetRouteInfoFunction = ( match : DataRouteMatch ) => {
151153 hasLoader : boolean ;
152- hasClientLoader : boolean ; // TODO: Can this be read from match.route?
153- hasShouldRevalidate : boolean | undefined ; // TODO: Can this be read from match.route?
154+ hasClientLoader : boolean ;
155+ hasShouldRevalidate : boolean ;
154156} ;
155157
156158type FetchAndDecodeFunction = (
@@ -159,23 +161,33 @@ type FetchAndDecodeFunction = (
159161 targetRoutes ?: string [ ]
160162) => Promise < { status : number ; data : DecodedSingleFetchResults } > ;
161163
162- export function getSingleFetchDataStrategy (
164+ export function getTurboStreamSingleFetchDataStrategy (
163165 getRouter : ( ) => DataRouter ,
164- getRouteInfo : GetRouteInfoFunction ,
166+ manifest : AssetsManifest ,
167+ routeModules : RouteModules ,
165168 ssr : boolean ,
166169 basename : string | undefined
167170) : DataStrategyFunction {
168- let dataStrategy = getSingleFetchDataStrategyImpl (
171+ let dataStrategy = getTurboStreamSingleFetchDataStrategyImpl (
169172 getRouter ,
170- getRouteInfo ,
173+ ( match : DataRouteMatch ) => {
174+ let manifestRoute = manifest . routes [ match . route . id ] ;
175+ invariant ( manifestRoute , "Route not found in manifest" ) ;
176+ let routeModule = routeModules [ match . route . id ] ;
177+ return {
178+ hasLoader : manifestRoute . hasLoader ,
179+ hasClientLoader : manifestRoute . hasClientLoader ,
180+ hasShouldRevalidate : Boolean ( routeModule ?. shouldRevalidate ) ,
181+ } ;
182+ } ,
171183 fetchAndDecodeViaTurboStream ,
172184 ssr ,
173185 basename
174186 ) ;
175187 return async ( args ) => args . unstable_runClientMiddleware ( dataStrategy ) ;
176188}
177189
178- export function getSingleFetchDataStrategyImpl (
190+ export function getTurboStreamSingleFetchDataStrategyImpl (
179191 getRouter : ( ) => DataRouter ,
180192 getRouteInfo : GetRouteInfoFunction ,
181193 fetchAndDecode : FetchAndDecodeFunction ,
@@ -192,7 +204,7 @@ export function getSingleFetchDataStrategyImpl(
192204 }
193205
194206 let foundRevalidatingServerLoader = matches . some ( ( m ) => {
195- let { hasLoader, hasClientLoader } = getRouteInfo ( m . route . id ) ;
207+ let { hasLoader, hasClientLoader } = getRouteInfo ( m ) ;
196208 return m . unstable_shouldCallHandler ( ) && hasLoader && ! hasClientLoader ;
197209 } ) ;
198210 if ( ! ssr && ! foundRevalidatingServerLoader ) {
@@ -298,7 +310,7 @@ async function nonSsrStrategy(
298310 matchesToLoad . map ( ( m ) =>
299311 m . resolve ( async ( handler ) => {
300312 try {
301- let { hasClientLoader } = getRouteInfo ( m . route . id ) ;
313+ let { hasClientLoader } = getRouteInfo ( m ) ;
302314 // Need to pass through a `singleFetch` override handler so
303315 // clientLoader's can still call server loaders through `.data`
304316 // requests
@@ -350,7 +362,7 @@ async function singleFetchLoaderNavigationStrategy(
350362 routeDfds [ i ] . resolve ( ) ;
351363 let routeId = m . route . id ;
352364 let { hasLoader, hasClientLoader, hasShouldRevalidate } =
353- getRouteInfo ( routeId ) ;
365+ getRouteInfo ( m ) ;
354366
355367 let defaultShouldRevalidate =
356368 ! m . unstable_shouldRevalidateArgs ||
0 commit comments