Skip to content

Commit

Permalink
Remove recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jun 14, 2024
1 parent 59400f7 commit d0bd620
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/astro/src/core/build/plugins/plugin-prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,12 @@ function getNonPrerenderOnlyChunks(bundle: Rollup.OutputBundle, internals: Build

// From the `nonPrerenderedEntryChunks`, we crawl all the imports/dynamicImports to find all
// other chunks that are use by the non-prerendered runtime
const nonPrerenderOnlyChunks = new Set();
for (const entryChunk of nonPrerenderOnlyEntryChunks) {
crawlChunk(entryChunk);
}

function crawlChunk(chunk: Rollup.OutputChunk) {
if (nonPrerenderOnlyChunks.has(chunk)) return;
nonPrerenderOnlyChunks.add(chunk);
const nonPrerenderOnlyChunks = new Set(nonPrerenderOnlyEntryChunks);
for (const chunk of nonPrerenderOnlyChunks) {
for (const importFileName of chunk.imports) {
const importChunk = bundle[importFileName];
if (importChunk?.type === 'chunk') {
crawlChunk(importChunk);
nonPrerenderOnlyChunks.add(importChunk);
}
}
for (const dynamicImportFileName of chunk.dynamicImports) {
Expand All @@ -98,7 +92,7 @@ function getNonPrerenderOnlyChunks(bundle: Rollup.OutputBundle, internals: Build
dynamicImportChunk?.type === 'chunk' &&
!prerenderOnlyEntryChunks.has(dynamicImportChunk)
) {
crawlChunk(dynamicImportChunk);
nonPrerenderOnlyChunks.add(dynamicImportChunk);
}
}
}
Expand Down

0 comments on commit d0bd620

Please sign in to comment.