From 712669f6056a61964760212868494042f55a4445 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Wed, 9 Aug 2023 10:21:24 -0700 Subject: [PATCH] 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 --- packages/next/src/build/webpack/loaders/next-app-loader.ts | 7 +++++-- .../parallel-routes-and-interception.test.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/next/src/build/webpack/loaders/next-app-loader.ts b/packages/next/src/build/webpack/loaders/next-app-loader.ts index b6298b2131..559756f0d4 100644 --- a/packages/next/src/build/webpack/loaders/next-app-loader.ts +++ b/packages/next/src/build/webpack/loaders/next-app-loader.ts @@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() { pathname: string ): [string, string | string[]][] => { const matched: Record = {} + 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] } } diff --git a/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts b/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts index 865d6fdabe..b18a87b368 100644 --- a/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts +++ b/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts @@ -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()