Skip to content

Commit

Permalink
fix(flight-manifest-plugin): passthrough intercepting routes in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jul 20, 2023
1 parent b583617 commit 4f9f081
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down
10 changes: 5 additions & 5 deletions packages/next/src/shared/lib/router/utils/app-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down

0 comments on commit 4f9f081

Please sign in to comment.