@@ -199,6 +199,28 @@ const isRouteVirtualModule = (id: string): boolean => {
199
199
return isRouteEntryModuleId ( id ) || isRouteChunkModuleId ( id ) ;
200
200
} ;
201
201
202
+ const isServerBuildVirtualModuleId = ( id : string ) : boolean => {
203
+ return id . split ( "?" ) [ 0 ] === virtual . serverBuild . id ;
204
+ } ;
205
+
206
+ const getServerBuildFile = ( viteManifest : Vite . Manifest ) : string => {
207
+ let serverBuildIds = Object . keys ( viteManifest ) . filter (
208
+ isServerBuildVirtualModuleId
209
+ ) ;
210
+
211
+ invariant (
212
+ serverBuildIds . length <= 1 ,
213
+ "Multiple server build files found in manifest"
214
+ ) ;
215
+
216
+ invariant (
217
+ serverBuildIds . length === 1 ,
218
+ "Server build file not found in manifest"
219
+ ) ;
220
+
221
+ return viteManifest [ serverBuildIds [ 0 ] ] . file ;
222
+ } ;
223
+
202
224
export type ServerBundleBuildConfig = {
203
225
routes : RouteManifest ;
204
226
serverBundleId : string ;
@@ -1518,7 +1540,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1518
1540
viteConfig ,
1519
1541
ctx . reactRouterConfig ,
1520
1542
serverBuildDirectory ,
1521
- ssrViteManifest [ virtual . serverBuild . id ] . file ,
1543
+ getServerBuildFile ( ssrViteManifest ) ,
1522
1544
clientBuildDirectory
1523
1545
) ;
1524
1546
}
@@ -1531,7 +1553,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1531
1553
viteConfig ,
1532
1554
ctx . reactRouterConfig ,
1533
1555
serverBuildDirectory ,
1534
- ssrViteManifest [ virtual . serverBuild . id ] . file ,
1556
+ getServerBuildFile ( ssrViteManifest ) ,
1535
1557
clientBuildDirectory
1536
1558
) ;
1537
1559
}
@@ -2406,19 +2428,28 @@ async function handlePrerender(
2406
2428
serverBuildPath
2407
2429
) ;
2408
2430
2409
- let routes = createPrerenderRoutes ( build . routes ) ;
2431
+ let routes = createPrerenderRoutes ( reactRouterConfig . routes ) ;
2432
+ for ( let path of build . prerender ) {
2433
+ let matches = matchRoutes ( routes , `/${ path } /` . replace ( / ^ \/ \/ + / , "/" ) ) ;
2434
+ if ( ! matches ) {
2435
+ throw new Error (
2436
+ `Unable to prerender path because it does not match any routes: ${ path } `
2437
+ ) ;
2438
+ }
2439
+ }
2440
+
2441
+ let buildRoutes = createPrerenderRoutes ( build . routes ) ;
2410
2442
let headers = {
2411
2443
// Header that can be used in the loader to know if you're running at
2412
2444
// build time or runtime
2413
2445
"X-React-Router-Prerender" : "yes" ,
2414
2446
} ;
2415
2447
for ( let path of build . prerender ) {
2416
2448
// Ensure we have a leading slash for matching
2417
- let matches = matchRoutes ( routes , `/${ path } /` . replace ( / ^ \/ \/ + / , "/" ) ) ;
2418
- invariant (
2419
- matches ,
2420
- `Unable to prerender path because it does not match any routes: ${ path } `
2421
- ) ;
2449
+ let matches = matchRoutes ( buildRoutes , `/${ path } /` . replace ( / ^ \/ \/ + / , "/" ) ) ;
2450
+ if ( ! matches ) {
2451
+ continue ;
2452
+ }
2422
2453
// When prerendering a resource route, we don't want to pass along the
2423
2454
// `.data` file since we want to prerender the raw Response returned from
2424
2455
// the loader. Presumably this is for routes where a file extension is
0 commit comments