@@ -597,17 +597,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
597597 routes
598598 ) ;
599599
600- let isSpaMode =
601- ! ctx . reactRouterConfig . ssr && ctx . reactRouterConfig . prerender == null ;
602-
603- let routeIdsToImport = new Set ( Object . keys ( routes ) ) ;
604- if ( isSpaMode ) {
605- // In SPA mode, we only pre-render the top-level index route; for all
606- // other routes we stub out their imports, as they (and their deps) may
607- // not be compatible with server-side rendering. This also helps keep
608- // the build fast
609- routeIdsToImport = getRootRouteIds ( routes ) ;
610- }
600+ let isSpaMode = isSpaModeEnabled ( ctx . reactRouterConfig ) ;
611601
612602 return `
613603 import * as entryServer from ${ JSON . stringify (
@@ -616,17 +606,19 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
616606 ${ Object . keys ( routes )
617607 . map ( ( key , index ) => {
618608 let route = routes [ key ] ! ;
619- if ( routeIdsToImport . has ( key ) ) {
609+ if ( isSpaMode && key !== "root" ) {
610+ // In SPA mode, we only pre-render to the root route and it's `HydrateFallback`.
611+ // Therefore, we can stub all other routes with an empty module as they
612+ // (and their deps) may not be compatible with server-side rendering.
613+ // This also helps keep the build fast.
614+ return `const route${ index } = { default: () => null };` ;
615+ } else {
620616 return `import * as route${ index } from ${ JSON . stringify (
621617 resolveFileUrl (
622618 ctx ,
623619 resolveRelativeRouteFilePath ( route , ctx . reactRouterConfig )
624620 )
625621 ) } ;`;
626- } else {
627- // we're not importing the route since we won't be rendering
628- // it via SSR; just stub it out
629- return `const route${ index } = { default: () => null };` ;
630622 }
631623 } )
632624 . join ( "\n" ) }
@@ -2605,17 +2597,6 @@ function groupRoutesByParentId(manifest: GenericRouteManifest) {
26052597 return routes ;
26062598}
26072599
2608- /**
2609- * Return the route ids associated with the top-level index route
2610- *
2611- * i.e. "root", the top-level index route's id, and (if applicable) the ids of
2612- * any top-level layout/path-less routes in between
2613- */
2614- function getRootRouteIds ( manifest : GenericRouteManifest ) : Set < string > {
2615- const matches = matchRoutes ( createPrerenderRoutes ( manifest ) , "/" ) ;
2616- return new Set ( matches ?. filter ( Boolean ) . map ( ( m ) => m . route . id ) || [ ] ) ;
2617- }
2618-
26192600// Create a skeleton route tree of paths
26202601function createPrerenderRoutes (
26212602 manifest : GenericRouteManifest ,
0 commit comments