@@ -22,8 +22,6 @@ import {
2222} from 'path' ;
2323import zlib from 'zlib' ;
2424import { hasValue } from '../../app/shared/empty.util' ;
25- import { ThemeConfig } from '../../config/theme.config' ;
26-
2725import {
2826 HashedFileMapping ,
2927 ID ,
@@ -46,7 +44,7 @@ export class ServerHashedFileMapping extends HashedFileMapping {
4644 public readonly indexPath : string ;
4745 private readonly indexContent : string ;
4846
49- protected readonly headLinks : Set < HeadLink > = new Set ( ) ;
47+ protected readonly headLinks : Map < string , HeadLink > = new Map ( ) ;
5048
5149 constructor (
5250 private readonly root : string ,
@@ -112,33 +110,30 @@ export class ServerHashedFileMapping extends HashedFileMapping {
112110 return hashPath ;
113111 }
114112
115- /**
116- * Add CSS for all configured themes to the mapping
117- * @param themeConfigurations
118- */
119- addThemeStyles ( themeConfigurations : ThemeConfig [ ] ) {
120- for ( const themeConfiguration of themeConfigurations ) {
121- const path = `${ this . root } /${ themeConfiguration . name } -theme.css` ;
122- const hashPath = this . add ( path ) ;
113+ addThemeStyle ( theme : string , prefetch = true ) {
114+ const path = `${ this . root } /${ theme } -theme.css` ;
115+ const hashPath = this . add ( path ) ;
123116
117+ if ( prefetch ) {
124118 // We know this CSS is likely needed, so we can avoid a FOUC by retrieving it in advance
125119 // Angular does the same for global styles, but doesn't "know" about our themes
126120 this . addHeadLink ( {
127121 path,
128122 rel : 'prefetch' ,
129123 as : 'style' ,
130124 } ) ;
131-
132- this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.br' ) ;
133- this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.gz' ) ;
134125 }
126+
127+ // We know theme CSS has been compressed already
128+ this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.br' ) ;
129+ this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.gz' ) ;
135130 }
136131
137132 /**
138133 * Include a head link for a given resource to the index HTML.
139134 */
140135 addHeadLink ( headLink : HeadLink ) {
141- this . headLinks . add ( headLink ) ;
136+ this . headLinks . set ( headLink . path , headLink ) ;
142137 }
143138
144139 private renderHeadLink ( link : HeadLink ) : string {
@@ -176,7 +171,7 @@ export class ServerHashedFileMapping extends HashedFileMapping {
176171 root . querySelector ( 'head' )
177172 . appendChild ( `<script id="${ ID } " type="application/json">${ JSON . stringify ( out ) } </script>` as any ) ;
178173
179- for ( const headLink of this . headLinks ) {
174+ for ( const headLink of this . headLinks . values ( ) ) {
180175 root . querySelector ( 'head' )
181176 . appendChild ( this . renderHeadLink ( headLink ) as any ) ;
182177 }
0 commit comments