Fix index normalizing for app outputs (#11099)

This ensures we don't apply the index output normalizing for app paths which was previously already gated for prerenders but not all routes.
This commit is contained in:
JJ Kasper
2024-01-31 14:13:23 -08:00
committed by GitHub
parent 3bad73401b
commit 4027a18337
7 changed files with 92 additions and 23 deletions

View File

@@ -0,0 +1,5 @@
---
"@vercel/next": patch
---
Fix index normalizing for app outputs

View File

@@ -1128,11 +1128,11 @@ export async function serverBuild({
); );
}); });
} }
let outputName = path.posix.join(entryDirectory, pageNoExt);
let outputName = normalizeIndexOutput( if (!group.isAppRouter && !group.isAppRouteHandler) {
path.posix.join(entryDirectory, pageNoExt), outputName = normalizeIndexOutput(outputName, true);
true }
);
// If this is a PPR page, then we should prefix the output name. // If this is a PPR page, then we should prefix the output name.
if (isPPR) { if (isPPR) {
@@ -1443,9 +1443,10 @@ export async function serverBuild({
continue; continue;
} }
const pathname = normalizeIndexOutput( const pathname = path.posix.join(
path.posix.join('./', entryDirectory, route === '/' ? '/index' : route), './',
true entryDirectory,
route === '/' ? '/index' : route
); );
if (lambdas[pathname]) { if (lambdas[pathname]) {

View File

@@ -2053,6 +2053,11 @@ export const onPrerenderRoute =
let isAppPathRoute = false; let isAppPathRoute = false;
// experimentalPPR signals app path route
if (appDir && experimentalPPR) {
isAppPathRoute = true;
}
// TODO: leverage manifest to determine app paths more accurately // TODO: leverage manifest to determine app paths more accurately
if (appDir && srcRoute && (!dataRoute || dataRoute?.endsWith('.rsc'))) { if (appDir && srcRoute && (!dataRoute || dataRoute?.endsWith('.rsc'))) {
isAppPathRoute = true; isAppPathRoute = true;
@@ -2184,7 +2189,6 @@ export const onPrerenderRoute =
if (routeKey !== '/index' && routeKey.endsWith('/index')) { if (routeKey !== '/index' && routeKey.endsWith('/index')) {
routeKey = `${routeKey}/index`; routeKey = `${routeKey}/index`;
routeFileNoExt = routeKey; routeFileNoExt = routeKey;
origRouteFileNoExt = routeKey;
} }
} }
@@ -2255,15 +2259,20 @@ export const onPrerenderRoute =
const lambdaId = pageLambdaMap[outputSrcPathPage]; const lambdaId = pageLambdaMap[outputSrcPathPage];
lambda = lambdas[lambdaId]; lambda = lambdas[lambdaId];
} else { } else {
const outputSrcPathPage = normalizeIndexOutput( let outputSrcPathPage =
srcRoute == null srcRoute == null
? outputPathPageOrig ? outputPathPageOrig
: path.posix.join( : path.posix.join(
entryDirectory, entryDirectory,
srcRoute === '/' ? '/index' : srcRoute srcRoute === '/' ? '/index' : srcRoute
), );
if (!isAppPathRoute) {
outputSrcPathPage = normalizeIndexOutput(
outputSrcPathPage,
isServerMode isServerMode
); );
}
lambda = lambdas[outputSrcPathPage]; lambda = lambdas[outputSrcPathPage];
} }
@@ -2464,10 +2473,17 @@ export const onPrerenderRoute =
routesManifest, routesManifest,
locale locale
); );
const localeOutputPathPage = normalizeIndexOutput( let localeOutputPathPage = path.posix.join(
path.posix.join(entryDirectory, localeRouteFileNoExt), entryDirectory,
localeRouteFileNoExt
);
if (!isAppPathRoute) {
localeOutputPathPage = normalizeIndexOutput(
localeOutputPathPage,
isServerMode isServerMode
); );
}
const origPrerenderPage = prerenders[outputPathPage]; const origPrerenderPage = prerenders[outputPathPage];
prerenders[localeOutputPathPage] = { prerenders[localeOutputPathPage] = {
@@ -2969,14 +2985,17 @@ export async function getMiddlewareBundle({
} }
if (routesManifest?.basePath) { if (routesManifest?.basePath) {
shortPath = normalizeIndexOutput( const isAppPathRoute = !!appPathRoutesManifest[shortPath];
path.posix.join(
shortPath = path.posix.join(
'./', './',
routesManifest?.basePath, routesManifest?.basePath,
shortPath.replace(/^\//, '') shortPath.replace(/^\//, '')
),
true
); );
if (!isAppPathRoute) {
shortPath = normalizeIndexOutput(shortPath, true);
}
} }
worker.edgeFunction.name = shortPath; worker.edgeFunction.name = shortPath;

View File

@@ -0,0 +1,7 @@
export default function Page() {
return (
<>
<p>dynamic-index</p>
</>
)
}

View File

@@ -18,6 +18,21 @@
} }
], ],
"probes": [ "probes": [
{
"path": "/dynamic-index/hello/index",
"status": 200,
"mustContain": "dynamic-index"
},
{
"path": "/dynamic-index/hello/index",
"status": 200,
"mustContain": ":",
"mustNotContain": "<html",
"headers": {
"RSC": 1,
"Next-Router-Prefetch": 1
}
},
{ {
"path": "/rewritten-to-dashboard", "path": "/rewritten-to-dashboard",
"status": 200, "status": 200,

View File

@@ -0,0 +1,7 @@
export default function Page() {
return (
<>
<p>dynamic-index</p>
</>
)
}

View File

@@ -18,6 +18,21 @@
} }
], ],
"probes": [ "probes": [
{
"path": "/dynamic-index/hello/index",
"status": 200,
"mustContain": "dynamic-index"
},
{
"path": "/dynamic-index/hello/index",
"status": 200,
"mustContain": ":",
"mustNotContain": "<html",
"headers": {
"RSC": 1,
"Next-Router-Prefetch": 1
}
},
{ {
"path": "/rewritten-to-dashboard", "path": "/rewritten-to-dashboard",
"status": 200, "status": 200,