1+ import type { AgnosticDataRouteMatch } from "@remix-run/router" ;
12import type { Location } from "react-router-dom" ;
23import { parsePath } from "react-router-dom" ;
34
45import type { AssetsManifest } from "./entry" ;
5- import type { ClientRoute } from "./routes" ;
6- import type { RouteMatch } from "./routeMatching" ;
7- // import { matchClientRoutes } from "./routeMatching";
86import type { RouteModules , RouteModule } from "./routeModules" ;
97import { loadRouteModule } from "./routeModules" ;
108
@@ -223,7 +221,7 @@ export type LinkDescriptor = HtmlLinkDescriptor | PrefetchPageDescriptor;
223221 * loaded already.
224222 */
225223export function getLinksForMatches (
226- matches : RouteMatch < ClientRoute > [ ] ,
224+ matches : AgnosticDataRouteMatch [ ] ,
227225 routeModules : RouteModules ,
228226 manifest : AssetsManifest
229227) : LinkDescriptor [ ] {
@@ -322,12 +320,16 @@ export function isHtmlLinkDescriptor(
322320}
323321
324322export async function getStylesheetPrefetchLinks (
325- matches : RouteMatch < ClientRoute > [ ] ,
323+ matches : AgnosticDataRouteMatch [ ] ,
324+ manifest : AssetsManifest ,
326325 routeModules : RouteModules
327326) : Promise < HtmlLinkDescriptor [ ] > {
328327 let links = await Promise . all (
329328 matches . map ( async ( match ) => {
330- let mod = await loadRouteModule ( match . route , routeModules ) ;
329+ let mod = await loadRouteModule (
330+ manifest . routes [ match . route . id ] ,
331+ routeModules
332+ ) ;
331333 return mod . links ? mod . links ( ) : [ ] ;
332334 } )
333335 ) ;
@@ -346,19 +348,20 @@ export async function getStylesheetPrefetchLinks(
346348// This is ridiculously identical to transition.ts `filterMatchesToLoad`
347349export function getNewMatchesForLinks (
348350 page : string ,
349- nextMatches : RouteMatch < ClientRoute > [ ] ,
350- currentMatches : RouteMatch < ClientRoute > [ ] ,
351+ nextMatches : AgnosticDataRouteMatch [ ] ,
352+ currentMatches : AgnosticDataRouteMatch [ ] ,
353+ manifest : AssetsManifest ,
351354 location : Location ,
352355 mode : "data" | "assets"
353- ) : RouteMatch < ClientRoute > [ ] {
356+ ) : AgnosticDataRouteMatch [ ] {
354357 let path = parsePathPatch ( page ) ;
355358
356- let isNew = ( match : RouteMatch < ClientRoute > , index : number ) => {
359+ let isNew = ( match : AgnosticDataRouteMatch , index : number ) => {
357360 if ( ! currentMatches [ index ] ) return true ;
358361 return match . route . id !== currentMatches [ index ] . route . id ;
359362 } ;
360363
361- let matchPathChanged = ( match : RouteMatch < ClientRoute > , index : number ) => {
364+ let matchPathChanged = ( match : AgnosticDataRouteMatch , index : number ) => {
362365 return (
363366 // param change, /users/123 -> /users/456
364367 currentMatches [ index ] . pathname !== match . pathname ||
@@ -376,29 +379,32 @@ export function getNewMatchesForLinks(
376379 ? // this is really similar to stuff in transition.ts, maybe somebody smarter
377380 // than me (or in less of a hurry) can share some of it. You're the best.
378381 nextMatches . filter ( ( match , index ) => {
379- if ( ! match . route . hasLoader ) {
382+ let manifestRoute = manifest . routes [ match . route . id ] ;
383+ if ( ! manifestRoute . hasLoader ) {
380384 return false ;
381385 }
382386
383387 if ( isNew ( match , index ) || matchPathChanged ( match , index ) ) {
384388 return true ;
385389 }
386390
387- if ( match . route . shouldReload ) {
388- return match . route . shouldReload ( {
389- params : match . params ,
390- prevUrl : new URL (
391- location . pathname + location . search + location . hash ,
392- window . origin
393- ) ,
394- url : new URL ( page , window . origin ) ,
395- } ) ;
391+ if ( match . route . shouldRevalidate ) {
392+ // TODO: Implement
393+ // return match.route.shouldRevalidate({
394+ // params: match.params,
395+ // prevUrl: new URL(
396+ // location.pathname + location.search + location.hash,
397+ // window.origin
398+ // ),
399+ // url: new URL(page, window.origin),
400+ // });
396401 }
397402 return true ;
398403 } )
399404 : nextMatches . filter ( ( match , index ) => {
405+ let manifestRoute = manifest . routes [ match . route . id ] ;
400406 return (
401- ( mode === "assets" || match . route . hasLoader ) &&
407+ ( mode === "assets" || manifestRoute . hasLoader ) &&
402408 ( isNew ( match , index ) || matchPathChanged ( match , index ) )
403409 ) ;
404410 } ) ;
@@ -408,7 +414,7 @@ export function getNewMatchesForLinks(
408414
409415export function getDataLinkHrefs (
410416 page : string ,
411- matches : RouteMatch < ClientRoute > [ ] ,
417+ matches : AgnosticDataRouteMatch [ ] ,
412418 manifest : AssetsManifest
413419) : string [ ] {
414420 let path = parsePathPatch ( page ) ;
@@ -425,7 +431,7 @@ export function getDataLinkHrefs(
425431}
426432
427433export function getModuleLinkHrefs (
428- matches : RouteMatch < ClientRoute > [ ] ,
434+ matches : AgnosticDataRouteMatch [ ] ,
429435 manifestPatch : AssetsManifest
430436) : string [ ] {
431437 return dedupeHrefs (
@@ -446,7 +452,7 @@ export function getModuleLinkHrefs(
446452// need to include them in a page prefetch, this gives us the list to remove
447453// while deduping.
448454function getCurrentPageModulePreloadHrefs (
449- matches : RouteMatch < ClientRoute > [ ] ,
455+ matches : AgnosticDataRouteMatch [ ] ,
450456 manifest : AssetsManifest
451457) : string [ ] {
452458 return dedupeHrefs (
0 commit comments