File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed
packages/angular/ssr/src/routes Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -327,21 +327,31 @@ function appendPreloadToMetadata(
327327 metadata : ServerConfigRouteTreeNodeMetadata ,
328328 includeDynamicImports : boolean ,
329329) : void {
330- if ( ! entryPointToBrowserMapping ) {
330+ const existingPreloads = metadata . preload ?? [ ] ;
331+ if ( ! entryPointToBrowserMapping || existingPreloads . length >= MODULE_PRELOAD_MAX ) {
331332 return ;
332333 }
333334
334335 const preload = entryPointToBrowserMapping [ entryName ] ;
336+ if ( ! preload ?. length ) {
337+ return ;
338+ }
339+
340+ // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed.
341+ const combinedPreloads : Set < string > = new Set ( existingPreloads ) ;
342+ for ( const { dynamicImport, path } of preload ) {
343+ if ( dynamicImport && ! includeDynamicImports ) {
344+ continue ;
345+ }
346+
347+ combinedPreloads . add ( path ) ;
335348
336- if ( preload ?. length ) {
337- // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed.
338- const preloadPaths =
339- preload
340- . filter ( ( { dynamicImport } ) => includeDynamicImports || ! dynamicImport )
341- . map ( ( { path } ) => path ) ?? [ ] ;
342- const combinedPreloads = [ ...( metadata . preload ?? [ ] ) , ...preloadPaths ] ;
343- metadata . preload = Array . from ( new Set ( combinedPreloads ) ) . slice ( 0 , MODULE_PRELOAD_MAX ) ;
349+ if ( combinedPreloads . size === MODULE_PRELOAD_MAX ) {
350+ break ;
351+ }
344352 }
353+
354+ metadata . preload = Array . from ( combinedPreloads ) ;
345355}
346356
347357/**
You can’t perform that action at this time.
0 commit comments