@@ -526,7 +526,7 @@ export default ${JSON.stringify(route.css)}
526526 const manifest = JSON . parse ( asset . source as string ) as Manifest ;
527527
528528 for ( const info of Object . values ( manifest ) ) {
529- // Utility-file(_app/_layout/_error)'s CSS Modules can be hoisted into
529+ // Utility-file(_app/_layout/_error)'s CSS can be hoisted into
530530 // shared chunks like "server-entry", not just route chunks.
531531 // Replace placeholders in any emitted JS chunk that contains one.
532532 if ( ! / \. (?: c | m ) ? j s $ / . test ( info . file ) ) continue ;
@@ -611,22 +611,31 @@ async function collectRouteCss(
611611 if ( seen . has ( current ) ) continue ;
612612 seen . add ( current ) ;
613613
614+ // Modules may be registered under either their public id or Vite's
615+ // internal "\0" id, depending on when they entered the graph.
614616 let mod = env . moduleGraph . getModuleById ( current ) ??
615617 env . moduleGraph . getModuleById ( `\0${ current } ` ) ;
616618
617- if ( mod === undefined || mod . transformResult === null ) {
619+ if ( mod ?. transformResult == null ) {
620+ // Dev transforms are lazy. Force Vite to load the module before we
621+ // inspect its imports for CSS dependencies.
618622 await env . fetchModule ( current ) ;
619623 mod = env . moduleGraph . getModuleById ( current ) ??
620624 env . moduleGraph . getModuleById ( `\0${ current } ` ) ;
621625 }
622626
627+ // Some ids still won't resolve into the SSR graph (for example, if Vite
628+ // does not materialize the module after fetch). Skip those and keep
629+ // collecting CSS from the remaining graph.
623630 if ( mod === undefined ) continue ;
624631
625632 if ( mod . id !== null && CSS_LANG_REG . test ( mod . id ) ) {
626633 out . add ( mod . url ) ;
627634 continue ;
628635 }
629636
637+ // Layout/app/error utility files can reach CSS through nested component
638+ // imports, so walk the full SSR import graph for this route module.
630639 mod . importedModules . forEach ( ( imported ) => {
631640 if ( imported . id !== null ) {
632641 queue . push ( imported . id ) ;
0 commit comments