diff --git a/packages/next/src/server-build.ts b/packages/next/src/server-build.ts index cc3ccbb9ba0..b8bfc4ec666 100644 --- a/packages/next/src/server-build.ts +++ b/packages/next/src/server-build.ts @@ -1024,6 +1024,7 @@ export async function serverBuild({ isCorrectMiddlewareOrder, prerenderBypassToken: prerenderManifest.bypassToken || '', nextVersion, + appPathRoutesManifest: appPathRoutesManifest || {}, }); const isNextDataServerResolving = diff --git a/packages/next/src/utils.ts b/packages/next/src/utils.ts index 562c6b1231d..e0e750bfd98 100644 --- a/packages/next/src/utils.ts +++ b/packages/next/src/utils.ts @@ -2378,6 +2378,7 @@ export async function getMiddlewareBundle({ isCorrectMiddlewareOrder, prerenderBypassToken, nextVersion, + appPathRoutesManifest, }: { config: Config; entryPath: string; @@ -2386,6 +2387,7 @@ export async function getMiddlewareBundle({ routesManifest: RoutesManifest; isCorrectMiddlewareOrder: boolean; nextVersion: string; + appPathRoutesManifest: Record; }): Promise<{ staticRoutes: Route[]; dynamicRouteMap: Map; @@ -2550,9 +2552,15 @@ export async function getMiddlewareBundle({ shortPath.startsWith('app/') && (shortPath.endsWith('/page') || shortPath.endsWith('/route')) ) { - shortPath = - shortPath.replace(/^app\//, '').replace(/(^|\/)(page|route)$/, '') || - 'index'; + const ogRoute = shortPath.replace(/^app\//, '/'); + shortPath = ( + appPathRoutesManifest[ogRoute] || + shortPath.replace(/(^|\/)(page|route)$/, '') + ).replace(/^\//, ''); + + if (!shortPath || shortPath === '/') { + shortPath = 'index'; + } } if (routesManifest?.basePath) { diff --git a/packages/next/test/fixtures/00-app-dir/app/(newroot)/dashboard/another-edge/page.js b/packages/next/test/fixtures/00-app-dir/app/(newroot)/dashboard/another-edge/page.js new file mode 100644 index 00000000000..d6994df3e69 --- /dev/null +++ b/packages/next/test/fixtures/00-app-dir/app/(newroot)/dashboard/another-edge/page.js @@ -0,0 +1,9 @@ +export const runtime = 'experimental-edge' + +export default function AnotherPage(props) { + return ( + <> +

hello from newroot/dashboard/another

+ + ); +} diff --git a/packages/next/test/fixtures/00-app-dir/vercel.json b/packages/next/test/fixtures/00-app-dir/vercel.json index 30c5f08710a..1586df55998 100644 --- a/packages/next/test/fixtures/00-app-dir/vercel.json +++ b/packages/next/test/fixtures/00-app-dir/vercel.json @@ -6,6 +6,11 @@ } ], "probes": [ + { + "path": "/dashboard/another-edge", + "status": 200, + "mustContain": "hello from newroot/dashboard/another" + }, { "path": "/dynamic/category-1/id-1", "status": 200, diff --git a/packages/next/test/integration/index.test.js b/packages/next/test/integration/index.test.js index bedd1b65495..3af72c40b59 100644 --- a/packages/next/test/integration/index.test.js +++ b/packages/next/test/integration/index.test.js @@ -78,7 +78,7 @@ if (parseInt(process.versions.node.split('.')[0], 10) >= 16) { expect(edgeFunctions.size).toBe(3); expect(buildResult.output['edge']).toBeDefined(); expect(buildResult.output['index']).toBeDefined(); - expect(buildResult.output['index/index']).toBeDefined(); + // expect(buildResult.output['index/index']).toBeDefined(); }); it('should show error from basePath with legacy monorepo build', async () => {