@@ -68,7 +68,6 @@ export class Application implements ServerApplication {
6868 #fsWatchListeners: Array < EventEmitter > = [ ]
6969 #bundler: Bundler = new Bundler ( this )
7070 #renderer: Renderer = new Renderer ( this )
71- #renderCache: Map < string , Map < string , [ string , any ] > > = new Map ( )
7271 #injects: Map < 'compilation' | 'hmr' | 'ssr' , TransformFn [ ] > = new Map ( )
7372 #reloading = false
7473
@@ -270,9 +269,9 @@ export class Application implements ServerApplication {
270269 const hmrable = this . isHMRable ( mod . url )
271270 const update = ( { url } : Module ) => {
272271 if ( trimModuleExt ( url ) === '/app' ) {
273- this . #renderCache . clear ( )
272+ this . #renderer . clearCache ( )
274273 } else if ( url . startsWith ( '/pages/' ) ) {
275- this . #renderCache . delete ( toPagePath ( url ) )
274+ this . #renderer . clearCache ( url )
276275 this . #pageRouting. update ( this . createRouteModule ( url ) )
277276 } else if ( url . startsWith ( '/api/' ) ) {
278277 this . #apiRouting. update ( this . createRouteModule ( url ) )
@@ -297,9 +296,9 @@ export class Application implements ServerApplication {
297296 } )
298297 } else if ( this . #modules. has ( url ) ) {
299298 if ( trimModuleExt ( url ) === '/app' ) {
300- this . #renderCache . clear ( )
299+ this . #renderer . clearCache ( )
301300 } else if ( url . startsWith ( '/pages/' ) ) {
302- this . #renderCache . delete ( toPagePath ( url ) )
301+ this . #renderer . clearCache ( toPagePath ( url ) )
303302 this . #pageRouting. removeRoute ( toPagePath ( url ) )
304303 } else if ( url . startsWith ( '/api/' ) ) {
305304 this . #apiRouting. removeRoute ( toPagePath ( url ) )
@@ -426,7 +425,7 @@ export class Application implements ServerApplication {
426425 }
427426
428427 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 ( ) => {
430429 return await this . #renderer. renderPage ( router , nestedModules )
431430 } )
432431 return ret [ 1 ]
@@ -440,26 +439,30 @@ export class Application implements ServerApplication {
440439 const path = router . pathname + router . query . toString ( )
441440
442441 if ( ! this . isSSRable ( loc . pathname ) ) {
443- const [ html ] = await this . useRenderCache ( '-' , 'spa-index' , async ( ) => {
442+ const [ html ] = await this . #renderer . useCache ( '-' , 'spa-index' , async ( ) => {
444443 return [ await this . #renderer. renderSPAIndexPage ( ) , null ]
445444 } )
446445 return [ status , html ]
447446 }
448447
449448 if ( pagePath === '' ) {
450- const [ html ] = await this . useRenderCache ( '404' , path , async ( ) => {
449+ const [ html ] = await this . #renderer . useCache ( '404' , path , async ( ) => {
451450 return [ await this . #renderer. render404Page ( router ) , null ]
452451 } )
453452 return [ status , html ]
454453 }
455454
456- const [ html ] = await this . useRenderCache ( pagePath , path , async ( ) => {
455+ const [ html ] = await this . #renderer . useCache ( pagePath , path , async ( ) => {
457456 let [ html , data ] = await this . #renderer. renderPage ( router , nestedModules )
458457 return [ html , data ]
459458 } )
460459 return [ status , html ]
461460 }
462461
462+ getCodeInjects ( phase : 'compilation' | 'hmr' | 'ssr' ) {
463+ return this . #injects. get ( phase )
464+ }
465+
463466 createFSWatcher ( ) : EventEmitter {
464467 const e = new EventEmitter ( )
465468 this . #fsWatchListeners. push ( e )
@@ -1204,30 +1207,6 @@ export class Application implements ServerApplication {
12041207 }
12051208 }
12061209
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-
12311210 /** check a page whether is able to SSR. */
12321211 private isSSRable ( pathname : string ) : boolean {
12331212 const { ssr } = this . config
0 commit comments