Skip to content

Commit

Permalink
[next] Fix edge runtime for route groups (#9764)
Browse files Browse the repository at this point in the history
This ensures we use the correct short name when generating edge
functions with route groups from app directory.

Example deployment with fix can be seen here
https://next-debug-edge-runtime-1ar7agbjh-vtest314-ijjk-testing.vercel.app/group-no-layout

Fixes: vercel/next.js#43458
  • Loading branch information
ijjk committed Apr 7, 2023
1 parent 52b2892 commit 7a9a519
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/next/src/server-build.ts
Expand Up @@ -1024,6 +1024,7 @@ export async function serverBuild({
isCorrectMiddlewareOrder,
prerenderBypassToken: prerenderManifest.bypassToken || '',
nextVersion,
appPathRoutesManifest: appPathRoutesManifest || {},
});

const isNextDataServerResolving =
Expand Down
14 changes: 11 additions & 3 deletions packages/next/src/utils.ts
Expand Up @@ -2378,6 +2378,7 @@ export async function getMiddlewareBundle({
isCorrectMiddlewareOrder,
prerenderBypassToken,
nextVersion,
appPathRoutesManifest,
}: {
config: Config;
entryPath: string;
Expand All @@ -2386,6 +2387,7 @@ export async function getMiddlewareBundle({
routesManifest: RoutesManifest;
isCorrectMiddlewareOrder: boolean;
nextVersion: string;
appPathRoutesManifest: Record<string, string>;
}): Promise<{
staticRoutes: Route[];
dynamicRouteMap: Map<string, RouteWithSrc>;
Expand Down Expand Up @@ -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) {
Expand Down
@@ -0,0 +1,9 @@
export const runtime = 'experimental-edge'

export default function AnotherPage(props) {
return (
<>
<p>hello from newroot/dashboard/another</p>
</>
);
}
5 changes: 5 additions & 0 deletions packages/next/test/fixtures/00-app-dir/vercel.json
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/test/integration/index.test.js
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 7a9a519

Please sign in to comment.