@@ -68,7 +68,6 @@ export class Application implements ServerApplication {
68
68
#fsWatchListeners: Array < EventEmitter > = [ ]
69
69
#bundler: Bundler = new Bundler ( this )
70
70
#renderer: Renderer = new Renderer ( this )
71
- #renderCache: Map < string , Map < string , [ string , any ] > > = new Map ( )
72
71
#injects: Map < 'compilation' | 'hmr' | 'ssr' , TransformFn [ ] > = new Map ( )
73
72
#reloading = false
74
73
@@ -270,9 +269,9 @@ export class Application implements ServerApplication {
270
269
const hmrable = this . isHMRable ( mod . url )
271
270
const update = ( { url } : Module ) => {
272
271
if ( trimModuleExt ( url ) === '/app' ) {
273
- this . #renderCache . clear ( )
272
+ this . #renderer . clearCache ( )
274
273
} else if ( url . startsWith ( '/pages/' ) ) {
275
- this . #renderCache . delete ( toPagePath ( url ) )
274
+ this . #renderer . clearCache ( url )
276
275
this . #pageRouting. update ( this . createRouteModule ( url ) )
277
276
} else if ( url . startsWith ( '/api/' ) ) {
278
277
this . #apiRouting. update ( this . createRouteModule ( url ) )
@@ -297,9 +296,9 @@ export class Application implements ServerApplication {
297
296
} )
298
297
} else if ( this . #modules. has ( url ) ) {
299
298
if ( trimModuleExt ( url ) === '/app' ) {
300
- this . #renderCache . clear ( )
299
+ this . #renderer . clearCache ( )
301
300
} else if ( url . startsWith ( '/pages/' ) ) {
302
- this . #renderCache . delete ( toPagePath ( url ) )
301
+ this . #renderer . clearCache ( toPagePath ( url ) )
303
302
this . #pageRouting. removeRoute ( toPagePath ( url ) )
304
303
} else if ( url . startsWith ( '/api/' ) ) {
305
304
this . #apiRouting. removeRoute ( toPagePath ( url ) )
@@ -426,7 +425,7 @@ export class Application implements ServerApplication {
426
425
}
427
426
428
427
const cacheKey = router . pathname + router . query . toString ( )
429
- const ret = await this . useRenderCache ( pagePath , cacheKey , async ( ) => {
428
+ const ret = await this . #renderer . useCache ( pagePath , cacheKey , async ( ) => {
430
429
return await this . #renderer. renderPage ( router , nestedModules )
431
430
} )
432
431
return ret [ 1 ]
@@ -440,26 +439,30 @@ export class Application implements ServerApplication {
440
439
const path = router . pathname + router . query . toString ( )
441
440
442
441
if ( ! this . isSSRable ( loc . pathname ) ) {
443
- const [ html ] = await this . useRenderCache ( '-' , 'spa-index' , async ( ) => {
442
+ const [ html ] = await this . #renderer . useCache ( '-' , 'spa-index' , async ( ) => {
444
443
return [ await this . #renderer. renderSPAIndexPage ( ) , null ]
445
444
} )
446
445
return [ status , html ]
447
446
}
448
447
449
448
if ( pagePath === '' ) {
450
- const [ html ] = await this . useRenderCache ( '404' , path , async ( ) => {
449
+ const [ html ] = await this . #renderer . useCache ( '404' , path , async ( ) => {
451
450
return [ await this . #renderer. render404Page ( router ) , null ]
452
451
} )
453
452
return [ status , html ]
454
453
}
455
454
456
- const [ html ] = await this . useRenderCache ( pagePath , path , async ( ) => {
455
+ const [ html ] = await this . #renderer . useCache ( pagePath , path , async ( ) => {
457
456
let [ html , data ] = await this . #renderer. renderPage ( router , nestedModules )
458
457
return [ html , data ]
459
458
} )
460
459
return [ status , html ]
461
460
}
462
461
462
+ getCodeInjects ( phase : 'compilation' | 'hmr' | 'ssr' ) {
463
+ return this . #injects. get ( phase )
464
+ }
465
+
463
466
createFSWatcher ( ) : EventEmitter {
464
467
const e = new EventEmitter ( )
465
468
this . #fsWatchListeners. push ( e )
@@ -1204,30 +1207,6 @@ export class Application implements ServerApplication {
1204
1207
}
1205
1208
}
1206
1209
1207
- private async useRenderCache (
1208
- namespace : string ,
1209
- key : string ,
1210
- render : ( ) => Promise < [ string , any ] >
1211
- ) : Promise < [ string , any ] > {
1212
- let cache = this . #renderCache. get ( namespace )
1213
- if ( cache === undefined ) {
1214
- cache = new Map ( )
1215
- this . #renderCache. set ( namespace , cache )
1216
- }
1217
- const cached = cache . get ( key )
1218
- if ( cached !== undefined ) {
1219
- return cached
1220
- }
1221
- const ret = await render ( )
1222
- if ( namespace !== '-' ) {
1223
- this . #injects. get ( 'ssr' ) ?. forEach ( transform => {
1224
- ret [ 0 ] = transform ( key , ret [ 0 ] )
1225
- } )
1226
- }
1227
- cache . set ( key , ret )
1228
- return ret
1229
- }
1230
-
1231
1210
/** check a page whether is able to SSR. */
1232
1211
private isSSRable ( pathname : string ) : boolean {
1233
1212
const { ssr } = this . config
0 commit comments