From b6202d668bc835009fa6972557a9247f968a818b Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Sat, 25 Feb 2023 16:53:53 +0100 Subject: [PATCH] fix duplicate link type asset generation --- .../webpack/plugins/next-types-plugin.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/next-types-plugin.ts b/packages/next/src/build/webpack/plugins/next-types-plugin.ts index a9feaecf6b216..5ea026922df27 100644 --- a/packages/next/src/build/webpack/plugins/next-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/next-types-plugin.ts @@ -122,24 +122,22 @@ async function collectNamedSlots(layoutPath: string) { return slots } -let edgeRouteTypes = new Set() -let nodeRouteTypes = new Set() +const edgeRouteTypes: string[] = [] +const nodeRouteTypes: string[] = [] export const pageFiles = new Set() function createRouteDefinitions() { - const fallback = !edgeRouteTypes.size && !nodeRouteTypes.size ? 'string' : '' + const fallback = + !edgeRouteTypes.length && !nodeRouteTypes.length ? 'string' : '' let routeTypes = '' edgeRouteTypes.forEach((route) => { routeTypes += ` | ${route}\n` }) - nodeRouteTypes.forEach((route) => { - if (!edgeRouteTypes.has(route)) { - routeTypes += ` | ${route}\n` - } + routeTypes += ` | ${route}\n` }) return `declare module 'next' { @@ -271,7 +269,7 @@ export class NextTypesPlugin { .join('/') } - ;(this.isEdgeServer ? edgeRouteTypes : nodeRouteTypes).add( + ;(this.isEdgeServer ? edgeRouteTypes : nodeRouteTypes).push( `\`${route}\${Suffix}\`` ) } @@ -358,9 +356,9 @@ export class NextTypesPlugin { // Clear routes if (this.isEdgeServer) { - edgeRouteTypes = new Set() + edgeRouteTypes.length = 0 } else { - nodeRouteTypes = new Set() + nodeRouteTypes.length = 0 } compilation.chunkGroups.forEach((chunkGroup: any) => { @@ -396,9 +394,11 @@ export class NextTypesPlugin { await Promise.all(promises) if (this.typedRoutes) { - pageFiles.forEach((file) => { - this.collectPage(file) - }) + if (this.dev && !this.isEdgeServer) { + pageFiles.forEach((file) => { + this.collectPage(file) + }) + } const linkTypePath = path.join('types', 'link.d.ts') const assetPath =