* Appends preload information to the metadata object based on the specified entry-point and chunk mappings. * * This function extracts preload data for a given entry-point from the provided chunk mappings. It adds the * corresponding browser bundles to the metadata's preload list, ensuring no dup
( entryName: string, entryPointToBrowserMapping: EntryPointToBrowserMapping, metadata: ServerConfigRouteTreeNodeMetadata, )
| 360 | * preloads to a predefined maximum. |
| 361 | */ |
| 362 | function appendPreloadToMetadata( |
| 363 | entryName: string, |
| 364 | entryPointToBrowserMapping: EntryPointToBrowserMapping, |
| 365 | metadata: ServerConfigRouteTreeNodeMetadata, |
| 366 | ): void { |
| 367 | const existingPreloads = metadata.preload ?? []; |
| 368 | if (!entryPointToBrowserMapping || existingPreloads.length >= MODULE_PRELOAD_MAX) { |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | const preload = entryPointToBrowserMapping[entryName]; |
| 373 | if (!preload?.length) { |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | // Merge existing preloads with new ones, ensuring uniqueness and limiting the total to the maximum allowed. |
| 378 | const combinedPreloads: Set<string> = new Set(existingPreloads); |
| 379 | for (const href of preload) { |
| 380 | combinedPreloads.add(href); |
| 381 | if (combinedPreloads.size === MODULE_PRELOAD_MAX) { |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | metadata.preload = Array.from(combinedPreloads); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Handles SSG (Static Site Generation) routes by invoking `getPrerenderParams` and yielding |
no test coverage detected