@@ -9,6 +9,7 @@ export class StaticRouters {
9
9
readonly server : FileSystemRouter ;
10
10
readonly client : FileSystemRouter ;
11
11
readonly #routes_dump: string ;
12
+ readonly #hashed: Record < string , string > ;
12
13
13
14
constructor (
14
15
public baseDir : string ,
@@ -23,12 +24,14 @@ export class StaticRouters {
23
24
dir : join ( baseDir , buildDir , pageDir ) ,
24
25
style : "nextjs" ,
25
26
} ) ;
27
+ this . #hashed = require ( join ( baseDir , buildDir , ".meta.json" ) ) . hashed ;
26
28
this . #routes_dump = NJSON . stringify (
27
29
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
+ } )
32
35
) ,
33
36
{ omitStack : true }
34
37
) ;
@@ -46,21 +49,24 @@ export class StaticRouters {
46
49
console . error ( error , errorInfo ) ;
47
50
} ,
48
51
noStreaming,
52
+ staticHeaders,
49
53
} : {
50
54
Shell : React . ComponentType < { children : React . ReactElement } > ;
51
55
preloadScript ?: string ;
52
56
bootstrapModules ?: string [ ] ;
53
57
context ?: T ;
54
58
onError ?( error : unknown , errorInfo : React . ErrorInfo ) : string | void ;
55
59
noStreaming ?: boolean ;
60
+ staticHeaders ?: HeadersInit ;
56
61
}
57
62
) : Promise < Response | null > {
58
63
const { pathname, search } = new URL ( request . url ) ;
59
64
const staticResponse = await serveFromDir ( {
60
65
directory : this . buildDir ,
61
66
path : pathname ,
62
67
} ) ;
63
- if ( staticResponse ) return new Response ( staticResponse ) ;
68
+ if ( staticResponse )
69
+ return new Response ( staticResponse , { headers : staticHeaders } ) ;
64
70
const serverSide = this . server . match ( request ) ;
65
71
if ( ! serverSide ) return null ;
66
72
const clientSide = this . client . match ( request ) ;
@@ -106,7 +112,11 @@ export class StaticRouters {
106
112
]
107
113
. filter ( Boolean )
108
114
. join ( ";" ) ,
109
- bootstrapModules,
115
+ bootstrapModules : bootstrapModules ?. map ( ( name ) => {
116
+ const hash = this . #hashed[ name ] ;
117
+ if ( hash ) return `${ name } ?${ hash } ` ;
118
+ return name ;
119
+ } ) ,
110
120
onError,
111
121
}
112
122
) ;
0 commit comments