From fb30dc03ce34a47d7b1d8f1e7aead97c5a5e3b08 Mon Sep 17 00:00:00 2001 From: GatsbyJS Bot Date: Fri, 5 May 2023 13:39:19 -0400 Subject: [PATCH] fix(gatsby): handle cyclic chunkgroup children (#38052) (#38061) (cherry picked from commit 272dacdbc5e334e6d7c8e918cfffac6f6d556577) Co-authored-by: Michal Piechowiak --- .../gatsby/src/utils/webpack/get-ssr-chunk-hashes.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/webpack/get-ssr-chunk-hashes.ts b/packages/gatsby/src/utils/webpack/get-ssr-chunk-hashes.ts index e8dfcb5ce6f78..f5181020bdc5e 100644 --- a/packages/gatsby/src/utils/webpack/get-ssr-chunk-hashes.ts +++ b/packages/gatsby/src/utils/webpack/get-ssr-chunk-hashes.ts @@ -6,8 +6,14 @@ type ChunkGroup = webpack.Compilation["chunkGroups"][0] function getHashes( chunkGroup: ChunkGroup, compilation: webpack.Compilation, - hashes: Array = [] + hashes: Array = [], + visitedChunkGroups: Set = new Set() ): Array { + if (visitedChunkGroups.has(chunkGroup)) { + return hashes + } + visitedChunkGroups.add(chunkGroup) + for (const chunk of chunkGroup.chunks) { if (!chunk.hash) { throw new Error( @@ -23,7 +29,7 @@ function getHashes( ) if (isNotImportedByAsyncRequires) { - getHashes(childChunkGroup, compilation, hashes) + getHashes(childChunkGroup, compilation, hashes, visitedChunkGroups) } }