From 39f9be7b215b16676fde3c420bd515d3517f2b33 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Dec 2023 14:54:21 -0500 Subject: [PATCH] fix(nextjs): Guard against injecting multiple times --- packages/nextjs/src/config/webpack.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 96cb0d3ae14e..0abe309c7406 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -625,6 +625,9 @@ function addFilesToExistingEntryPoint( if (typeof currentEntryPoint === 'string' || Array.isArray(currentEntryPoint)) { newEntryPoint = arrayify(currentEntryPoint); + if (newEntryPoint.some(entry => filesToInsert.includes(entry))) { + return; + } if (isDevMode) { // Inserting at beginning breaks dev mode so we insert at the end @@ -638,6 +641,9 @@ function addFilesToExistingEntryPoint( else if (typeof currentEntryPoint === 'object' && 'import' in currentEntryPoint) { const currentImportValue = currentEntryPoint.import; const newImportValue = arrayify(currentImportValue); + if (newImportValue.some(entry => filesToInsert.includes(entry))) { + return; + } if (isDevMode) { // Inserting at beginning breaks dev mode so we insert at the end