From d0bd6207d384ad024e94729553a2522429c41d4a Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 14 Jun 2024 18:26:01 +0800 Subject: [PATCH] Remove recursion --- .../src/core/build/plugins/plugin-prerender.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/astro/src/core/build/plugins/plugin-prerender.ts b/packages/astro/src/core/build/plugins/plugin-prerender.ts index b5781cbd8278..b7feb70e36a0 100644 --- a/packages/astro/src/core/build/plugins/plugin-prerender.ts +++ b/packages/astro/src/core/build/plugins/plugin-prerender.ts @@ -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) { @@ -98,7 +92,7 @@ function getNonPrerenderOnlyChunks(bundle: Rollup.OutputBundle, internals: Build dynamicImportChunk?.type === 'chunk' && !prerenderOnlyEntryChunks.has(dynamicImportChunk) ) { - crawlChunk(dynamicImportChunk); + nonPrerenderOnlyChunks.add(dynamicImportChunk); } } }