@@ -1384,6 +1384,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1384
1384
}
1385
1385
}
1386
1386
1387
+ const childCompilerPlugins = await asyncFlatten (
1388
+ childCompilerConfigFile . config . plugins ?? [ ]
1389
+ ) ;
1390
+
1387
1391
viteChildCompiler = await vite . createServer ( {
1388
1392
...viteUserConfig ,
1389
1393
// Ensure child compiler cannot overwrite the default cache directory
@@ -1397,8 +1401,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1397
1401
configFile : false ,
1398
1402
envFile : false ,
1399
1403
plugins : [
1400
- ...( childCompilerConfigFile . config . plugins ?? [ ] )
1401
- . flat ( )
1404
+ childCompilerPlugins
1402
1405
// Exclude this plugin from the child compiler to prevent an
1403
1406
// infinite loop (plugin creates a child compiler with the same
1404
1407
// plugin that creates another child compiler, repeat ad
@@ -1407,14 +1410,20 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
1407
1410
// production build because the child compiler is a Vite dev
1408
1411
// server and will generate incorrect manifests.
1409
1412
. filter (
1410
- ( plugin ) =>
1413
+ ( plugin ) : plugin is Vite . Plugin =>
1411
1414
typeof plugin === "object" &&
1412
1415
plugin !== null &&
1413
1416
"name" in plugin &&
1414
1417
plugin . name !== "react-router" &&
1415
1418
plugin . name !== "react-router:route-exports" &&
1416
1419
plugin . name !== "react-router:hmr-updates"
1417
- ) ,
1420
+ )
1421
+ // Remove server hooks to avoid conflicts with main dev server
1422
+ . map ( ( plugin ) => ( {
1423
+ ...plugin ,
1424
+ configureServer : undefined ,
1425
+ configurePreviewServer : undefined ,
1426
+ } ) ) ,
1418
1427
{
1419
1428
name : "react-router:override-optimize-deps" ,
1420
1429
config ( userConfig ) {
@@ -3509,3 +3518,17 @@ async function getEnvironmentsOptions(
3509
3518
function isNonNullable < T > ( x : T ) : x is NonNullable < T > {
3510
3519
return x != null ;
3511
3520
}
3521
+
3522
+ // Type and function copied from Vite
3523
+ type AsyncFlatten < T extends unknown [ ] > = T extends ( infer U ) [ ]
3524
+ ? Exclude < Awaited < U > , U [ ] > [ ]
3525
+ : never ;
3526
+
3527
+ async function asyncFlatten < T extends unknown [ ] > (
3528
+ arr : T
3529
+ ) : Promise < AsyncFlatten < T > > {
3530
+ do {
3531
+ arr = ( await Promise . all ( arr ) ) . flat ( Infinity ) as any ;
3532
+ } while ( arr . some ( ( v : any ) => v ?. then ) ) ;
3533
+ return arr as unknown [ ] as AsyncFlatten < T > ;
3534
+ }
0 commit comments