improve error message for conflicting parallel segments (#53803)

This is a follow-up to log both conflicting paths & a link to route group docs, which I believe is the only scenario someone could trigger this

- https://github.com/vercel/next.js/pull/53752
This commit is contained in:
Zack Tanner 2023-08-09 10:21:24 -07:00 committed by GitHub
parent 7d67f00f8f
commit 712669f605
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
pathname: string
): [string, string | string[]][] => {
const matched: Record<string, string | string[]> = {}
let existingChildrenPath: string | undefined
for (const appPath of normalizedAppPaths) {
if (appPath.startsWith(pathname + '/')) {
const rest = appPath.slice(pathname.length + 1).split('/')
// It is the actual page, mark it specially.
if (rest.length === 1 && rest[0] === 'page') {
existingChildrenPath = appPath
matched.children = PAGE_SEGMENT
continue
}
@ -464,12 +466,13 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
// avoid clobbering existing page segments
// if it's a valid parallel segment, the `children` property will be set appropriately
if (matched.children && matched.children !== rest[0]) {
if (existingChildrenPath && matched.children !== rest[0]) {
throw new Error(
`/You cannot have two parallel pages that resolve to the same path. Please check ${appPath}.`
`You cannot have two parallel pages that resolve to the same path. Please check ${existingChildrenPath} and ${appPath}. Refer to the route group docs for more information: https://nextjs.org/docs/app/building-your-application/routing/route-groups`
)
}
existingChildrenPath = appPath
matched.children = rest[0]
}
}

View file

@ -211,7 +211,7 @@ createNextDescribe(
await check(
() => next.cliOutput,
/You cannot have two parallel pages that resolve to the same path./i
/You cannot have two parallel pages that resolve to the same path\. Please check \/parallel\/\(new\)\/@baz\/nested-2\/page and \/parallel\/nested-2\/page\./i
)
}
await next.stop()