File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export async function addNonce(html: string): Promise<string> {
4242}
4343
4444/** Finds the Angular nonce in an HTML string. */
45- async function findNonce ( html : string ) : Promise < string | null > {
45+ export async function findNonce ( html : string ) : Promise < string | null > {
4646 // Inexpensive check to avoid parsing the HTML when we're sure there's no nonce.
4747 if ( ! NONCE_ATTR_PATTERN . test ( html ) ) {
4848 return null ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818 BuildOutputFileType ,
1919 createOutputFile ,
2020} from '../../tools/esbuild/bundler-files' ;
21+ import { findNonce } from '../index-file/nonce' ;
2122import { joinUrlParts } from '../url' ;
2223
2324export const SERVER_APP_MANIFEST_FILENAME = 'angular-app-manifest.mjs' ;
@@ -201,7 +202,7 @@ export async function generateAngularServerAppManifest(
201202
202203 const indexHtml = additionalHtmlOutputFiles . get ( INDEX_HTML_SERVER ) ?. text ;
203204 if ( indexHtml ) {
204- nonce = findNonce ( indexHtml ) ;
205+ nonce = ( await findNonce ( indexHtml ) ) ?? undefined ;
205206 }
206207
207208 // When routes have been extracted, mappings are no longer needed, as preloads will be included in the metadata.
@@ -263,12 +264,3 @@ function generateLazyLoadedFilesMappings(
263264
264265 return entryPointToBundles ;
265266}
266-
267- /**
268- * Finds the Angular nonce attribute value in an HTML string.
269- */
270- function findNonce ( html : string ) : string | undefined {
271- const match = / < [ a - z A - Z 0 - 9 - ] + [ ^ > ] * ?\s n g c s p n o n c e = (?: " ( [ ^ " ] * ) " | ' ( [ ^ ' ] * ) ' | ( \S + ) ) / i. exec ( html ) ;
272-
273- return match ? ( match [ 1 ] ?? match [ 2 ] ?? match [ 3 ] ) : undefined ;
274- }
Original file line number Diff line number Diff line change @@ -369,20 +369,27 @@ export class AngularServerApp {
369369 return html ;
370370 }
371371
372- this . inlineCriticalCssProcessor ??= createProcessor ( [ ...criticalCssPlans ] , {
373- preload : 'media-script' ,
374- nonce,
375- preloadFonts : true ,
376- inlineFonts : true ,
377- noscriptFallback : true ,
378- cache : true ,
379- logger : {
380- // eslint-disable-next-line no-console
381- warn : console . warn ,
382- } ,
383- } ) . process ;
372+ try {
373+ this . inlineCriticalCssProcessor ??= createProcessor ( [ ...criticalCssPlans ] , {
374+ preload : 'media-script' ,
375+ nonce,
376+ preloadFonts : true ,
377+ inlineFonts : true ,
378+ noscriptFallback : true ,
379+ cache : true ,
380+ logger : {
381+ // eslint-disable-next-line no-console
382+ warn : console . warn ,
383+ } ,
384+ } ) . process ;
384385
385- return this . inlineCriticalCssProcessor ( html ) ;
386+ return this . inlineCriticalCssProcessor ( html ) ;
387+ } catch ( error ) {
388+ // eslint-disable-next-line no-console
389+ console . error ( 'An error occurred while inlining critical CSS.' , error ) ;
390+
391+ return html ;
392+ }
386393 }
387394
388395 /**
You can’t perform that action at this time.
0 commit comments