@@ -13,6 +13,9 @@ import {
13
13
targetFromTargetString ,
14
14
} from '@angular-devkit/architect' ;
15
15
import { JsonObject } from '@angular-devkit/core' ;
16
+ import type { Type } from '@angular/core' ;
17
+ import type * as platformServer from '@angular/platform-server' ;
18
+ import assert from 'assert' ;
16
19
import * as fs from 'fs' ;
17
20
import * as path from 'path' ;
18
21
import { normalizeOptimization } from '../../utils' ;
@@ -74,24 +77,28 @@ async function _renderUniversal(
74
77
localeDirectory ,
75
78
) ;
76
79
77
- const { AppServerModule, renderModule } = await import ( serverBundlePath ) ;
80
+ const { AppServerModule, renderModule, ɵSERVER_CONTEXT } = ( await import ( serverBundlePath ) ) as {
81
+ renderModule : typeof platformServer . renderModule | undefined ;
82
+ ɵSERVER_CONTEXT : typeof platformServer . ɵSERVER_CONTEXT | undefined ;
83
+ AppServerModule : Type < unknown > | undefined ;
84
+ } ;
78
85
79
- const renderModuleFn : ( ( module : unknown , options : { } ) => Promise < string > ) | undefined =
80
- renderModule ;
81
-
82
- if ( ! ( renderModuleFn && AppServerModule ) ) {
83
- throw new Error (
84
- `renderModule method and/or AppServerModule were not exported from: ${ serverBundlePath } .` ,
85
- ) ;
86
- }
86
+ assert ( renderModule , `renderModule was not exported from: ${ serverBundlePath } .` ) ;
87
+ assert ( AppServerModule , `AppServerModule was not exported from: ${ serverBundlePath } .` ) ;
88
+ assert ( ɵSERVER_CONTEXT , `ɵSERVER_CONTEXT was not exported from: ${ serverBundlePath } .` ) ;
87
89
88
90
// Load platform server module renderer
89
- const renderOpts = {
91
+ let html = await renderModule ( AppServerModule , {
90
92
document : indexHtml ,
91
93
url : options . route ,
92
- } ;
94
+ extraProviders : [
95
+ {
96
+ provide : ɵSERVER_CONTEXT ,
97
+ useValue : 'app-shell' ,
98
+ } ,
99
+ ] ,
100
+ } ) ;
93
101
94
- let html = await renderModuleFn ( AppServerModule , renderOpts ) ;
95
102
// Overwrite the client index file.
96
103
const outputIndexPath = options . outputIndexPath
97
104
? path . join ( root , options . outputIndexPath )
0 commit comments