Unverified Commit 712669f6 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

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
parent 7d67f00f
...@@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() { ...@@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
pathname: string pathname: string
): [string, string | string[]][] => { ): [string, string | string[]][] => {
const matched: Record<string, string | string[]> = {} const matched: Record<string, string | string[]> = {}
let existingChildrenPath: string | undefined
for (const appPath of normalizedAppPaths) { for (const appPath of normalizedAppPaths) {
if (appPath.startsWith(pathname + '/')) { if (appPath.startsWith(pathname + '/')) {
const rest = appPath.slice(pathname.length + 1).split('/') const rest = appPath.slice(pathname.length + 1).split('/')
// It is the actual page, mark it specially. // It is the actual page, mark it specially.
if (rest.length === 1 && rest[0] === 'page') { if (rest.length === 1 && rest[0] === 'page') {
existingChildrenPath = appPath
matched.children = PAGE_SEGMENT matched.children = PAGE_SEGMENT
continue continue
} }
...@@ -464,12 +466,13 @@ const nextAppLoader: AppLoader = async function nextAppLoader() { ...@@ -464,12 +466,13 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
// avoid clobbering existing page segments // avoid clobbering existing page segments
// if it's a valid parallel segment, the `children` property will be set appropriately // 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( 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] matched.children = rest[0]
} }
} }
......
...@@ -211,7 +211,7 @@ createNextDescribe( ...@@ -211,7 +211,7 @@ createNextDescribe(
await check( await check(
() => next.cliOutput, () => 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() await next.stop()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment