@@ -41,10 +41,12 @@ export async function getHtmlTemplates(pwd: string, routes: ServerRoute[]) {
41
41
export function injectTemplates (
42
42
pwd : string ,
43
43
routes ?: ServerRoute [ ] ,
44
+ htmlTemplatePromise ?: ReturnType < typeof getHtmlTemplates > ,
44
45
) : Middleware < ServerEnv > {
45
46
return async ( c , next ) => {
46
47
if ( routes && ! c . get ( 'templates' ) ) {
47
- const templates = await getHtmlTemplates ( pwd , routes ) ;
48
+ const templates = await ( htmlTemplatePromise ||
49
+ getHtmlTemplates ( pwd , routes ) ) ;
48
50
c . set ( 'templates' , templates ) ;
49
51
}
50
52
@@ -149,9 +151,13 @@ export const injectResourcePlugin = (): ServerPlugin => ({
149
151
async prepare ( ) {
150
152
const { middlewares, routes, distDirectory : pwd } = api . useAppContext ( ) ;
151
153
154
+ let htmlTemplatePromise :
155
+ | ReturnType < typeof getHtmlTemplates >
156
+ | undefined ;
152
157
// In Production, should warmup server bundles on prepare.
153
158
if ( isProd ( ) ) {
154
159
getServerManifest ( pwd , routes || [ ] , console ) ;
160
+ htmlTemplatePromise = getHtmlTemplates ( pwd , routes || [ ] ) ;
155
161
}
156
162
157
163
middlewares . push ( {
@@ -163,7 +169,7 @@ export const injectResourcePlugin = (): ServerPlugin => ({
163
169
middlewares . push ( {
164
170
name : 'inject-html' ,
165
171
166
- handler : injectTemplates ( pwd , routes ) ,
172
+ handler : injectTemplates ( pwd , routes , htmlTemplatePromise ) ,
167
173
} ) ;
168
174
} ,
169
175
} ;
0 commit comments