Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate link type asset generation #46421

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/next/src/build/webpack/plugins/next-types-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,22 @@ async function collectNamedSlots(layoutPath: string) {
return slots
}

let edgeRouteTypes = new Set<string>()
let nodeRouteTypes = new Set<string>()
const edgeRouteTypes: string[] = []
const nodeRouteTypes: string[] = []

export const pageFiles = new Set<string>()

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' {
Expand Down Expand Up @@ -271,7 +269,7 @@ export class NextTypesPlugin {
.join('/')
}

;(this.isEdgeServer ? edgeRouteTypes : nodeRouteTypes).add(
;(this.isEdgeServer ? edgeRouteTypes : nodeRouteTypes).push(
`\`${route}\${Suffix}\``
)
}
Expand Down Expand Up @@ -358,9 +356,9 @@ export class NextTypesPlugin {

// Clear routes
if (this.isEdgeServer) {
edgeRouteTypes = new Set<string>()
edgeRouteTypes.length = 0
} else {
nodeRouteTypes = new Set<string>()
nodeRouteTypes.length = 0
}

compilation.chunkGroups.forEach((chunkGroup: any) => {
Expand Down Expand Up @@ -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 =
Expand Down