@@ -9,6 +9,7 @@ export class StaticRouters {
99 readonly server : FileSystemRouter ;
1010 readonly client : FileSystemRouter ;
1111 readonly #routes_dump: string ;
12+ readonly #hashed: Record < string , string > ;
1213
1314 constructor (
1415 public baseDir : string ,
@@ -23,12 +24,14 @@ export class StaticRouters {
2324 dir : join ( baseDir , buildDir , pageDir ) ,
2425 style : "nextjs" ,
2526 } ) ;
27+ this . #hashed = require ( join ( baseDir , buildDir , ".meta.json" ) ) . hashed ;
2628 this . #routes_dump = NJSON . stringify (
2729 Object . fromEntries (
28- Object . entries ( this . client . routes ) . map ( ( [ path , filePath ] ) => [
29- path ,
30- "/" + relative ( join ( baseDir , buildDir ) , filePath ) ,
31- ] )
30+ Object . entries ( this . client . routes ) . map ( ( [ path , filePath ] ) => {
31+ let target = "/" + relative ( join ( baseDir , buildDir ) , filePath ) ;
32+ if ( this . #hashed[ target ] ) target += `?${ this . #hashed[ target ] } ` ;
33+ return [ path , target ] ;
34+ } )
3235 ) ,
3336 { omitStack : true }
3437 ) ;
@@ -46,21 +49,24 @@ export class StaticRouters {
4649 console . error ( error , errorInfo ) ;
4750 } ,
4851 noStreaming,
52+ staticHeaders,
4953 } : {
5054 Shell : React . ComponentType < { children : React . ReactElement } > ;
5155 preloadScript ?: string ;
5256 bootstrapModules ?: string [ ] ;
5357 context ?: T ;
5458 onError ?( error : unknown , errorInfo : React . ErrorInfo ) : string | void ;
5559 noStreaming ?: boolean ;
60+ staticHeaders ?: HeadersInit ;
5661 }
5762 ) : Promise < Response | null > {
5863 const { pathname, search } = new URL ( request . url ) ;
5964 const staticResponse = await serveFromDir ( {
6065 directory : this . buildDir ,
6166 path : pathname ,
6267 } ) ;
63- if ( staticResponse ) return new Response ( staticResponse ) ;
68+ if ( staticResponse )
69+ return new Response ( staticResponse , { headers : staticHeaders } ) ;
6470 const serverSide = this . server . match ( request ) ;
6571 if ( ! serverSide ) return null ;
6672 const clientSide = this . client . match ( request ) ;
@@ -106,7 +112,11 @@ export class StaticRouters {
106112 ]
107113 . filter ( Boolean )
108114 . join ( ";" ) ,
109- bootstrapModules,
115+ bootstrapModules : bootstrapModules ?. map ( ( name ) => {
116+ const hash = this . #hashed[ name ] ;
117+ if ( hash ) return `${ name } ?${ hash } ` ;
118+ return name ;
119+ } ) ,
110120 onError,
111121 }
112122 ) ;
0 commit comments