@@ -25,12 +25,7 @@ import { InlineCriticalCssProcessor } from './utils/inline-critical-css';
25
25
import { LRUCache } from './utils/lru-cache' ;
26
26
import { AngularBootstrap , renderAngular } from './utils/ng' ;
27
27
import { promiseWithAbort } from './utils/promise' ;
28
- import {
29
- buildPathWithParams ,
30
- joinUrlParts ,
31
- stripIndexHtmlFromURL ,
32
- stripLeadingSlash ,
33
- } from './utils/url' ;
28
+ import { buildPathWithParams , joinUrlParts , stripLeadingSlash } from './utils/url' ;
34
29
35
30
/**
36
31
* Maximum number of critical CSS entries the cache can store.
@@ -256,6 +251,7 @@ export class AngularServerApp {
256
251
return null ;
257
252
}
258
253
254
+ const url = new URL ( request . url ) ;
259
255
const platformProviders : StaticProvider [ ] = [ ] ;
260
256
261
257
// Initialize the response with status and headers if available.
@@ -285,7 +281,10 @@ export class AngularServerApp {
285
281
) ;
286
282
} else if ( renderMode === RenderMode . Client ) {
287
283
// Serve the client-side rendered version if the route is configured for CSR.
288
- return new Response ( await this . assets . getServerAsset ( 'index.csr.html' ) . text ( ) , responseInit ) ;
284
+ let html = await this . assets . getServerAsset ( 'index.csr.html' ) . text ( ) ;
285
+ html = await this . runTransformsOnHtml ( html , url ) ;
286
+
287
+ return new Response ( html , responseInit ) ;
289
288
}
290
289
291
290
const {
@@ -301,16 +300,9 @@ export class AngularServerApp {
301
300
} ) ;
302
301
}
303
302
304
- const url = new URL ( request . url ) ;
305
- let html = await assets . getIndexServerHtml ( ) . text ( ) ;
306
-
307
- // Skip extra microtask if there are no pre hooks.
308
- if ( hooks . has ( 'html:transform:pre' ) ) {
309
- html = await hooks . run ( 'html:transform:pre' , { html, url } ) ;
310
- }
311
-
312
303
this . boostrap ??= await bootstrap ( ) ;
313
-
304
+ let html = await assets . getIndexServerHtml ( ) . text ( ) ;
305
+ html = await this . runTransformsOnHtml ( html , url ) ;
314
306
html = await renderAngular (
315
307
html ,
316
308
this . boostrap ,
@@ -381,6 +373,21 @@ export class AngularServerApp {
381
373
382
374
return stripLeadingSlash ( assetPath ) ;
383
375
}
376
+
377
+ /**
378
+ * Runs the registered transform hooks on the given HTML content.
379
+ *
380
+ * @param html - The raw HTML content to be transformed.
381
+ * @param url - The URL associated with the HTML content, used for context during transformations.
382
+ * @returns A promise that resolves to the transformed HTML string.
383
+ */
384
+ private async runTransformsOnHtml ( html : string , url : URL ) : Promise < string > {
385
+ if ( this . hooks . has ( 'html:transform:pre' ) ) {
386
+ html = await this . hooks . run ( 'html:transform:pre' , { html, url } ) ;
387
+ }
388
+
389
+ return html ;
390
+ }
384
391
}
385
392
386
393
let angularServerApp : AngularServerApp | undefined ;
0 commit comments