mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 21:07:48 +00:00
[next] Support pre-generated pages without fallbacks with Partial Prerendering (#11183)
This commit is contained in:
@@ -304,19 +304,31 @@ export async function getRoutesManifest(
|
||||
return routesManifest;
|
||||
}
|
||||
|
||||
export async function getDynamicRoutes(
|
||||
entryPath: string,
|
||||
entryDirectory: string,
|
||||
dynamicPages: ReadonlyArray<string>,
|
||||
isDev?: boolean,
|
||||
routesManifest?: RoutesManifest,
|
||||
omittedRoutes?: ReadonlySet<string>,
|
||||
canUsePreviewMode?: boolean,
|
||||
bypassToken?: string,
|
||||
isServerMode?: boolean,
|
||||
dynamicMiddlewareRouteMap?: ReadonlyMap<string, RouteWithSrc>,
|
||||
experimentalPPR?: boolean
|
||||
): Promise<RouteWithSrc[]> {
|
||||
export async function getDynamicRoutes({
|
||||
entryPath,
|
||||
entryDirectory,
|
||||
dynamicPages,
|
||||
isDev,
|
||||
routesManifest,
|
||||
omittedRoutes,
|
||||
canUsePreviewMode,
|
||||
bypassToken,
|
||||
isServerMode,
|
||||
dynamicMiddlewareRouteMap,
|
||||
experimentalPPRRoutes,
|
||||
}: {
|
||||
entryPath: string;
|
||||
entryDirectory: string;
|
||||
dynamicPages: string[];
|
||||
isDev?: boolean;
|
||||
routesManifest?: RoutesManifest;
|
||||
omittedRoutes?: ReadonlySet<string>;
|
||||
canUsePreviewMode?: boolean;
|
||||
bypassToken?: string;
|
||||
isServerMode?: boolean;
|
||||
dynamicMiddlewareRouteMap?: ReadonlyMap<string, RouteWithSrc>;
|
||||
experimentalPPRRoutes: ReadonlySet<string>;
|
||||
}): Promise<RouteWithSrc[]> {
|
||||
if (routesManifest) {
|
||||
switch (routesManifest.version) {
|
||||
case 1:
|
||||
@@ -389,7 +401,7 @@ export async function getDynamicRoutes(
|
||||
];
|
||||
}
|
||||
|
||||
if (experimentalPPR) {
|
||||
if (experimentalPPRRoutes.has(page)) {
|
||||
let dest = route.dest?.replace(/($|\?)/, '.prefetch.rsc$1');
|
||||
|
||||
if (page === '/' || page === '/index') {
|
||||
@@ -919,6 +931,10 @@ export type NextPrerenderedRoutes = {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Routes that have their fallback behavior is disabled. All routes would've
|
||||
* been provided in the top-level `routes` key (`staticRoutes`).
|
||||
*/
|
||||
omittedRoutes: {
|
||||
[route: string]: {
|
||||
routeRegex: string;
|
||||
@@ -1298,8 +1314,6 @@ export async function getPrerenderManifest(
|
||||
prefetchDataRouteRegex,
|
||||
};
|
||||
} else {
|
||||
// Fallback behavior is disabled, all routes would've been provided
|
||||
// in the top-level `routes` key (`staticRoutes`).
|
||||
ret.omittedRoutes[lazyRoute] = {
|
||||
experimentalBypassFor,
|
||||
experimentalPPR,
|
||||
@@ -1923,6 +1937,7 @@ type OnPrerenderRouteArgs = {
|
||||
routesManifest?: RoutesManifest;
|
||||
isCorrectNotFoundRoutes?: boolean;
|
||||
isEmptyAllowQueryForPrendered?: boolean;
|
||||
omittedPrerenderRoutes: ReadonlySet<string>;
|
||||
};
|
||||
let prerenderGroup = 1;
|
||||
|
||||
@@ -1959,6 +1974,7 @@ export const onPrerenderRoute =
|
||||
routesManifest,
|
||||
isCorrectNotFoundRoutes,
|
||||
isEmptyAllowQueryForPrendered,
|
||||
omittedPrerenderRoutes,
|
||||
} = prerenderRouteArgs;
|
||||
|
||||
if (isBlocking && isFallback) {
|
||||
@@ -2383,25 +2399,31 @@ export const onPrerenderRoute =
|
||||
sourcePath = srcRoute;
|
||||
}
|
||||
|
||||
// The `experimentalStreamingLambdaPaths` stores the page without the
|
||||
// leading `/` and with the `/` rewritten to be `index`. We should
|
||||
// normalize the key so that it matches that key in the map.
|
||||
let key = srcRoute || routeKey;
|
||||
if (key === '/') {
|
||||
key = 'index';
|
||||
} else {
|
||||
if (!key.startsWith('/')) {
|
||||
throw new Error("Invariant: key doesn't start with /");
|
||||
let experimentalStreamingLambdaPath: string | undefined;
|
||||
if (experimentalPPR) {
|
||||
if (!experimentalStreamingLambdaPaths) {
|
||||
throw new Error(
|
||||
"Invariant: experimentalStreamingLambdaPaths doesn't exist"
|
||||
);
|
||||
}
|
||||
|
||||
key = key.substring(1);
|
||||
// If a source route exists, and it's not listed as an omitted route,
|
||||
// then use the src route as the basis for the experimental streaming
|
||||
// lambda path. If the route doesn't have a source route or it's not
|
||||
// omitted, then use the more specific `routeKey` as the basis.
|
||||
if (srcRoute && !omittedPrerenderRoutes.has(srcRoute)) {
|
||||
experimentalStreamingLambdaPath =
|
||||
experimentalStreamingLambdaPaths.get(
|
||||
pathnameToOutputName(entryDirectory, srcRoute)
|
||||
);
|
||||
} else {
|
||||
experimentalStreamingLambdaPath =
|
||||
experimentalStreamingLambdaPaths.get(
|
||||
pathnameToOutputName(entryDirectory, routeKey)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
key = path.posix.join(entryDirectory, key);
|
||||
|
||||
const experimentalStreamingLambdaPath =
|
||||
experimentalStreamingLambdaPaths?.get(key);
|
||||
|
||||
prerenders[outputPathPage] = new Prerender({
|
||||
expiration: initialRevalidate,
|
||||
lambda,
|
||||
@@ -2604,6 +2626,10 @@ export async function getStaticFiles(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the trailing `/index` from the output name if it's not the root if
|
||||
* the server mode is enabled.
|
||||
*/
|
||||
export function normalizeIndexOutput(
|
||||
outputName: string,
|
||||
isServerMode: boolean
|
||||
@@ -2624,6 +2650,19 @@ export function getNextServerPath(nextVersion: string) {
|
||||
: 'next/dist/next-server/server';
|
||||
}
|
||||
|
||||
export function pathnameToOutputName(entryDirectory: string, pathname: string) {
|
||||
if (pathname === '/') pathname = '/index';
|
||||
return path.posix.join(entryDirectory, pathname);
|
||||
}
|
||||
|
||||
export function getPostponeResumePathname(
|
||||
entryDirectory: string,
|
||||
pathname: string
|
||||
): string {
|
||||
if (pathname === '/') pathname = '/index';
|
||||
return path.posix.join(entryDirectory, '_next/postponed/resume', pathname);
|
||||
}
|
||||
|
||||
// update to leverage
|
||||
export function updateRouteSrc(
|
||||
route: Route,
|
||||
|
||||
Reference in New Issue
Block a user