@@ -81,28 +81,42 @@ export interface RendererContext {
81
81
_dependencySets : Record < string , ModuleDependencies >
82
82
_entrypoints : Identifier [ ]
83
83
_dynamicEntrypoints : Identifier [ ]
84
+ updateManifest : ( manifest : ClientManifest ) => void
84
85
}
85
86
86
87
export type RenderOptions = Partial < Exclude < RendererContext , 'entrypoints' > >
87
88
88
89
export function createRendererContext ( { clientManifest, publicPath, basedir, shouldPrefetch, shouldPreload } : RenderOptions ) : RendererContext {
89
- const manifest = normalizeClientManifest ( clientManifest ! )
90
- const manifestEntries = Object . entries ( manifest ) as [ Identifier , ResourceMeta ] [ ]
91
-
92
- return {
90
+ const ctx : RendererContext = {
93
91
// User customisation of output
94
92
shouldPrefetch : shouldPrefetch || ( ( ) => true ) ,
95
93
shouldPreload : shouldPreload || ( ( _file : string , asType : ModuleDependencies [ 'preload' ] [ string ] [ 'type' ] ) => [ 'module' , 'script' , 'style' ] . includes ( asType as string ) ) ,
96
94
// Manifest
97
- publicPath : ensureTrailingSlash ( publicPath || ( clientManifest as any ) . publicPath || '/' ) ,
98
- clientManifest : manifest ,
95
+ publicPath : ensureTrailingSlash ( publicPath || '/' ) ,
99
96
basedir,
97
+ clientManifest : undefined ! ,
98
+ updateManifest,
100
99
// Internal cache
101
- _dependencies : { } ,
102
- _dependencySets : { } ,
103
- _entrypoints : manifestEntries . filter ( e => e [ 1 ] . isEntry ) . map ( ( [ module ] ) => module ) ,
104
- _dynamicEntrypoints : manifestEntries . filter ( e => e [ 1 ] . isDynamicEntry ) . map ( ( [ module ] ) => module )
100
+ _dependencies : undefined ! ,
101
+ _dependencySets : undefined ! ,
102
+ _entrypoints : undefined ! ,
103
+ _dynamicEntrypoints : undefined !
104
+ }
105
+
106
+ function updateManifest ( clientManifest ?: ClientManifest ) {
107
+ const manifest = normalizeClientManifest ( clientManifest ! )
108
+ const manifestEntries = Object . entries ( manifest ) as [ Identifier , ResourceMeta ] [ ]
109
+ ctx . clientManifest = manifest
110
+ ctx . _dependencies = { }
111
+ ctx . _dependencySets = { }
112
+ ctx . _entrypoints = manifestEntries . filter ( e => e [ 1 ] . isEntry ) . map ( ( [ module ] ) => module )
113
+ ctx . _dynamicEntrypoints = manifestEntries . filter ( e => e [ 1 ] . isDynamicEntry ) . map ( ( [ module ] ) => module )
114
+ ctx . publicPath = ensureTrailingSlash ( publicPath || ( clientManifest as any ) . publicPath || '/' )
105
115
}
116
+
117
+ updateManifest ( clientManifest )
118
+
119
+ return ctx
106
120
}
107
121
108
122
export function isLegacyClientManifest ( clientManifest : ClientManifest | LegacyClientManifest ) : clientManifest is LegacyClientManifest {
@@ -358,6 +372,7 @@ export function createRenderer (createApp: any, renderOptions: RenderOptions & {
358
372
const rendererContext = createRendererContext ( renderOptions )
359
373
360
374
return {
375
+ rendererContext,
361
376
async renderToString ( ssrContext : SSRContext ) {
362
377
ssrContext . _registeredComponents = ssrContext . _registeredComponents || new Set ( )
363
378
0 commit comments