@@ -34,8 +34,7 @@ import { addTrailingSlash, joinUrlParts, stripIndexHtmlFromURL, stripTrailingSla
3434 * - A function that returns a `Promise<ApplicationRef>`, which resolves with the root application reference.
3535 */
3636export type AngularBootstrap =
37- | Type < unknown >
38- | ( ( context : BootstrapContext ) => Promise < ApplicationRef > ) ;
37+ Type < unknown > | ( ( context : BootstrapContext ) => Promise < ApplicationRef > ) ;
3938
4039/**
4140 * Renders an Angular application or module to an HTML string.
@@ -60,7 +59,12 @@ export async function renderAngular(
6059 serverContext : string ,
6160) : Promise <
6261 | { hasNavigationError : true }
63- | { hasNavigationError : boolean ; redirectTo ?: string ; content : ( ) => Promise < string > }
62+ | {
63+ hasNavigationError : boolean ;
64+ redirectTo ?: string ;
65+ content : ( ) => Promise < string > ;
66+ destroy : ( ) => void ;
67+ }
6468> {
6569 // A request to `http://www.example.com/page/index.html` will render the Angular route corresponding to `http://www.example.com/page`.
6670 const urlToRender = stripIndexHtmlFromURL ( url ) ;
@@ -134,6 +138,7 @@ export async function renderAngular(
134138 }
135139
136140 return {
141+ destroy : ( ) => void asyncDestroyPlatform ( platformRef ) ,
137142 hasNavigationError,
138143 redirectTo,
139144 content : ( ) =>
@@ -177,6 +182,10 @@ export function isNgModule(value: AngularBootstrap): value is Type<unknown> {
177182 * @param platformRef - The platform reference to be destroyed.
178183 */
179184function asyncDestroyPlatform ( platformRef : PlatformRef ) : Promise < void > {
185+ if ( platformRef . destroyed ) {
186+ return Promise . resolve ( ) ;
187+ }
188+
180189 return new Promise ( ( resolve ) => {
181190 setTimeout ( ( ) => {
182191 if ( ! platformRef . destroyed ) {
0 commit comments