From c16c85505a9303e9f906315dfd6fff1b6ac939cd Mon Sep 17 00:00:00 2001 From: Yoann Moinet Date: Tue, 17 Feb 2026 09:40:09 -0500 Subject: [PATCH] Use Set for chunk deduplication in rspack/webpack build report Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/plugins/build-report/src/xpack.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/plugins/build-report/src/xpack.ts b/packages/plugins/build-report/src/xpack.ts index 06eca82b..3f98139b 100644 --- a/packages/plugins/build-report/src/xpack.ts +++ b/packages/plugins/build-report/src/xpack.ts @@ -436,17 +436,20 @@ export const getXpackPlugin = // eslint-disable-next-line @typescript-eslint/no-explicit-any chunkGroup: any, visited: Set = new Set(), - ): Chunk[] => { + ): Set => { if (visited.has(chunkGroup)) { - return []; + return new Set(); } visited.add(chunkGroup); - const allChunks: Chunk[] = [...chunkGroup.chunks]; + const allChunks: Set = new Set(chunkGroup.chunks); // Recursively get chunks from child chunk groups (async chunks). for (const childGroup of chunkGroup.childrenIterable || []) { - allChunks.push(...getAllChunksFromGroup(childGroup, visited)); + const childChunks = getAllChunksFromGroup(childGroup, visited); + for (const chunk of childChunks) { + allChunks.add(chunk); + } } return allChunks; @@ -458,7 +461,7 @@ export const getXpackPlugin = let size = 0; // Get all chunks including async chunks from child chunk groups. const allChunks = getAllChunksFromGroup(entrypoint); - const entryFiles = allChunks.flatMap(getChunkFiles); + const entryFiles = Array.from(allChunks).flatMap(getChunkFiles); // FIXME This is not a 100% reliable way to get the entry filename. const entryFilename = entrypoint.chunks