@angular/ssr 19.1.6 → 19.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm2022/ssr.mjs CHANGED
@@ -838,26 +838,18 @@ async function* traverseRoutesConfig(options) {
838
838
  * preloads to a predefined maximum.
839
839
  */
840
840
  function appendPreloadToMetadata(entryName, entryPointToBrowserMapping, metadata, includeDynamicImports) {
841
- const existingPreloads = metadata.preload ?? [];
842
- if (!entryPointToBrowserMapping || existingPreloads.length >= MODULE_PRELOAD_MAX) {
841
+ if (!entryPointToBrowserMapping) {
843
842
  return;
844
843
  }
845
844
  const preload = entryPointToBrowserMapping[entryName];
846
- if (!preload?.length) {
847
- return;
848
- }
849
- // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed.
850
- const combinedPreloads = new Set(existingPreloads);
851
- for (const { dynamicImport, path } of preload) {
852
- if (dynamicImport && !includeDynamicImports) {
853
- continue;
854
- }
855
- combinedPreloads.add(path);
856
- if (combinedPreloads.size === MODULE_PRELOAD_MAX) {
857
- break;
858
- }
845
+ if (preload?.length) {
846
+ // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed.
847
+ const preloadPaths = preload
848
+ .filter(({ dynamicImport }) => includeDynamicImports || !dynamicImport)
849
+ .map(({ path }) => path) ?? [];
850
+ const combinedPreloads = [...(metadata.preload ?? []), ...preloadPaths];
851
+ metadata.preload = Array.from(new Set(combinedPreloads)).slice(0, MODULE_PRELOAD_MAX);
859
852
  }
860
- metadata.preload = Array.from(combinedPreloads);
861
853
  }
862
854
  /**
863
855
  * Handles SSG (Static Site Generation) routes by invoking `getPrerenderParams` and yielding
@@ -1062,6 +1054,7 @@ async function getRoutesFromAngularRouterConfig(bootstrap, document, url, invoke
1062
1054
  router.navigationTransitions.afterPreactivation()?.next?.();
1063
1055
  // Wait until the application is stable.
1064
1056
  await applicationRef.whenStable();
1057
+ const routesResults = [];
1065
1058
  const errors = [];
1066
1059
  let baseHref = injector.get(APP_BASE_HREF, null, { optional: true }) ??
1067
1060
  injector.get(PlatformLocation).getBaseHrefFromDOM();
@@ -1079,11 +1072,10 @@ async function getRoutesFromAngularRouterConfig(bootstrap, document, url, invoke
1079
1072
  if (errors.length) {
1080
1073
  return {
1081
1074
  baseHref,
1082
- routes: [],
1075
+ routes: routesResults,
1083
1076
  errors,
1084
1077
  };
1085
1078
  }
1086
- const routesResults = [];
1087
1079
  if (router.config.length) {
1088
1080
  // Retrieve all routes from the Angular router configuration.
1089
1081
  const traverseRoutes = traverseRoutesConfig({
@@ -1096,18 +1088,12 @@ async function getRoutesFromAngularRouterConfig(bootstrap, document, url, invoke
1096
1088
  includePrerenderFallbackRoutes,
1097
1089
  entryPointToBrowserMapping,
1098
1090
  });
1099
- const seenRoutes = new Set();
1100
- for await (const routeMetadata of traverseRoutes) {
1101
- if ('error' in routeMetadata) {
1102
- errors.push(routeMetadata.error);
1103
- continue;
1091
+ for await (const result of traverseRoutes) {
1092
+ if ('error' in result) {
1093
+ errors.push(result.error);
1104
1094
  }
1105
- // If a result already exists for the exact same route, subsequent matches should be ignored.
1106
- // This aligns with Angular's app router behavior, which prioritizes the first route.
1107
- const routePath = routeMetadata.route;
1108
- if (!seenRoutes.has(routePath)) {
1109
- routesResults.push(routeMetadata);
1110
- seenRoutes.add(routePath);
1095
+ else {
1096
+ routesResults.push(result);
1111
1097
  }
1112
1098
  }
1113
1099
  // This timeout is necessary to prevent 'adev' from hanging in production builds.