diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 12e9a4d386f9a..b4423c3b21e64 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -351,10 +351,16 @@ export class ClientReferenceManifestPlugin { // - app/foo/page -> app/foo // - app/(group)/@named/foo/page -> app/foo // - app/(group)/@named/(.)foo/page -> app/(.)foo - const groupName = normalizeAppPath(entryName).replace( - /\/(page|loading|layout|route|default|error|not-found)(\.tsx?|\.jsx?)?/g, - '' - ) + const preGroupName = entryName + .slice(0, entryName.lastIndexOf('/')) + .replace(/\/@[^/]+/g, '') + .replace(/\/\([^/]+\)/g, '') + + const groupName = normalizeAppPath(entryName, [ + 'loading', + 'layout', + ]).slice(1) + console.log({ preGroupName, groupName }) if (!manifestsPerGroup.has(groupName)) { manifestsPerGroup.set(groupName, []) diff --git a/packages/next/src/shared/lib/router/utils/app-paths.ts b/packages/next/src/shared/lib/router/utils/app-paths.ts index 59273bdce4ac4..667817259adf8 100644 --- a/packages/next/src/shared/lib/router/utils/app-paths.ts +++ b/packages/next/src/shared/lib/router/utils/app-paths.ts @@ -19,7 +19,10 @@ import { ensureLeadingSlash } from '../../page-path/ensure-leading-slash' * @param route the app route to normalize * @returns the normalized pathname */ -export function normalizeAppPath(route: string) { +export function normalizeAppPath(route: string, extraLeafs?: string[]) { + const DEFAULT_LEAFS = ['page', 'route'] + const mergedLeafs = [...(extraLeafs ?? []), ...DEFAULT_LEAFS] + return ensureLeadingSlash( route.split('/').reduce((pathname, segment, index, segments) => { // Empty segments are ignored. @@ -38,10 +41,7 @@ export function normalizeAppPath(route: string) { } // The last segment (if it's a leaf) should be ignored. - if ( - (segment === 'page' || segment === 'route') && - index === segments.length - 1 - ) { + if (mergedLeafs.includes(segment) && index === segments.length - 1) { return pathname }