Unverified Commit d3151279 authored by Aleksandr Kondrashov's avatar Aleksandr Kondrashov Committed by GitHub

Filter out duplicate paths in build output (#59858)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
Fixes #59775
Closes NEXT-1907
The build output includes a [normalized
path](https://github.com/vercel/next.js/blob/b3ad907d2bbe5f16988565ca6e99d434084bded0/packages/next/src/shared/lib/router/utils/app-paths.ts#L23)
that disregards groups and parallel segments, potentially causing
different routes to share the same normalized path. To address this,
I've implemented a check ensuring that the path is added to the
resulting array only once.

---------
Co-authored-by: 's avatarZack Tanner <zacktanner@gmail.com>
parent 9ce18c4d
...@@ -685,7 +685,7 @@ export default async function build( ...@@ -685,7 +685,7 @@ export default async function build(
const pagesPageKeys = Object.keys(mappedPages) const pagesPageKeys = Object.keys(mappedPages)
const conflictingAppPagePaths: [pagePath: string, appPath: string][] = [] const conflictingAppPagePaths: [pagePath: string, appPath: string][] = []
const appPageKeys: string[] = [] const appPageKeys = new Set<string>()
if (mappedAppPages) { if (mappedAppPages) {
denormalizedAppPages = Object.keys(mappedAppPages) denormalizedAppPages = Object.keys(mappedAppPages)
for (const appKey of denormalizedAppPages) { for (const appKey of denormalizedAppPages) {
...@@ -698,20 +698,19 @@ export default async function build( ...@@ -698,20 +698,19 @@ export default async function build(
appPath.replace(/^private-next-app-dir/, 'app'), appPath.replace(/^private-next-app-dir/, 'app'),
]) ])
} }
appPageKeys.push(normalizedAppPageKey) appPageKeys.add(normalizedAppPageKey)
} }
} }
const appPaths = Array.from(appPageKeys)
// Interception routes are modelled as beforeFiles rewrites // Interception routes are modelled as beforeFiles rewrites
rewrites.beforeFiles.push( rewrites.beforeFiles.push(...generateInterceptionRoutesRewrites(appPaths))
...generateInterceptionRoutesRewrites(appPageKeys)
)
const totalAppPagesCount = appPageKeys.length const totalAppPagesCount = appPaths.length
const pageKeys = { const pageKeys = {
pages: pagesPageKeys, pages: pagesPageKeys,
app: appPageKeys.length > 0 ? appPageKeys : undefined, app: appPaths.length > 0 ? appPaths : undefined,
} }
if (turboNextBuild) { if (turboNextBuild) {
...@@ -883,7 +882,7 @@ export default async function build( ...@@ -883,7 +882,7 @@ export default async function build(
(r: any) => !r.internal (r: any) => !r.internal
) )
const clientRouterFilters = createClientRouterFilter( const clientRouterFilters = createClientRouterFilter(
appPageKeys, appPaths,
config.experimental.clientRouterFilterRedirects config.experimental.clientRouterFilterRedirects
? nonInternalRedirects ? nonInternalRedirects
: [], : [],
......
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Layout({ children, header, footer }) {
return (
<>
{header}
{children}
{footer}
</>
)
}
export default function Page() {
return <div>Root Page</div>
}
...@@ -293,5 +293,17 @@ describe('Build Output', () => { ...@@ -293,5 +293,17 @@ describe('Build Output', () => {
expect(stdout).not.toContain('<buildId>') expect(stdout).not.toContain('<buildId>')
}) })
}) })
describe('With Parallel Routes', () => {
it('should not have duplicate paths that resolve to the same route', async () => {
const appDir = join(fixturesDir, 'with-parallel-routes')
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout.match(/○ \/root-page /g).length).toBe(1)
})
})
}) })
}) })
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