Skip to content

Commit

Permalink
Merge branch 'main' into update/node-vitest-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed May 23, 2024
2 parents 5e3ce1a + 6529a9a commit 4fc9f50
Show file tree
Hide file tree
Showing 116 changed files with 319 additions and 288 deletions.
2 changes: 0 additions & 2 deletions .changeset/breezy-fishes-develop.md

This file was deleted.

2 changes: 0 additions & 2 deletions .changeset/few-shrimps-attack.md

This file was deleted.

2 changes: 0 additions & 2 deletions .changeset/gorgeous-cycles-sell.md

This file was deleted.

18 changes: 18 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# vercel

## 34.2.2

### Patch Changes

- Fix related to erroring when a prefetch route is not provided but the route is PPR enabled ([#11638](https://github.com/vercel/vercel/pull/11638))

- Updated dependencies [[`8e44ef5b9`](https://github.com/vercel/vercel/commit/8e44ef5b9d2cdbe743c7f1e3534f182465fed9bf), [`61e6af374`](https://github.com/vercel/vercel/commit/61e6af3740296c11015d0c3da84ee205020b0ea6)]:
- @vercel/next@4.2.13

## 34.2.1

### Patch Changes

- Support incremental PPR for large applications ([#11625](https://github.com/vercel/vercel/pull/11625))

- Updated dependencies [[`73e558913`](https://github.com/vercel/vercel/commit/73e558913ab30ba097d7536a12fa8a7c967479f0)]:
- @vercel/next@4.2.12

## 34.2.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "34.2.0",
"version": "34.2.2",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@vercel/fun": "1.1.0",
"@vercel/go": "3.1.1",
"@vercel/hydrogen": "1.0.2",
"@vercel/next": "4.2.11",
"@vercel/next": "4.2.13",
"@vercel/node": "3.1.5",
"@vercel/python": "4.2.0",
"@vercel/redwood": "2.0.9",
Expand Down
14 changes: 14 additions & 0 deletions packages/next/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @vercel/next

## 4.2.13

### Patch Changes

- Fix static case for detecting when a page supports PPR ([#11635](https://github.com/vercel/vercel/pull/11635))

- Fix related to erroring when a prefetch route is not provided but the route is PPR enabled ([#11638](https://github.com/vercel/vercel/pull/11638))

## 4.2.12

### Patch Changes

- Support incremental PPR for large applications ([#11625](https://github.com/vercel/vercel/pull/11625))

## 4.2.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/next",
"version": "4.2.11",
"version": "4.2.13",
"license": "Apache-2.0",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
Expand Down
11 changes: 9 additions & 2 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,11 @@ export const build: BuildV2 = async ({
experimentalPPRRoutes.add(route);
}

const isAppPPREnabled = requiredServerFilesManifest
? requiredServerFilesManifest.config.experimental?.ppr === true ||
requiredServerFilesManifest.config.experimental?.ppr === 'incremental'
: false;

if (requiredServerFilesManifest) {
if (!routesManifest) {
throw new Error(
Expand Down Expand Up @@ -1413,6 +1418,7 @@ export const build: BuildV2 = async ({
hasIsr500Page,
variantsManifest,
experimentalPPRRoutes,
isAppPPREnabled,
});
}

Expand Down Expand Up @@ -1932,7 +1938,7 @@ export const build: BuildV2 = async ({
canUsePreviewMode,
bypassToken: prerenderManifest.bypassToken || '',
isServerMode,
experimentalPPRRoutes,
isAppPPREnabled: false,
hasActionOutputSupport: false,
}).then(arr =>
localizeDynamicRoutes(
Expand Down Expand Up @@ -1963,7 +1969,7 @@ export const build: BuildV2 = async ({
canUsePreviewMode,
bypassToken: prerenderManifest.bypassToken || '',
isServerMode,
experimentalPPRRoutes,
isAppPPREnabled: false,
hasActionOutputSupport: false,
}).then(arr =>
arr.map(route => {
Expand Down Expand Up @@ -2162,6 +2168,7 @@ export const build: BuildV2 = async ({
appPathRoutesManifest,
isSharedLambdas,
canUsePreviewMode,
isAppPPREnabled: false,
});

await Promise.all(
Expand Down
71 changes: 39 additions & 32 deletions packages/next/src/server-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export async function serverBuild({
requiredServerFilesManifest,
variantsManifest,
experimentalPPRRoutes,
isAppPPREnabled,
}: {
appPathRoutesManifest?: Record<string, string>;
dynamicPages: string[];
Expand Down Expand Up @@ -185,7 +186,15 @@ export async function serverBuild({
requiredServerFilesManifest: NextRequiredServerFilesManifest;
variantsManifest: VariantsManifest | null;
experimentalPPRRoutes: ReadonlySet<string>;
isAppPPREnabled: boolean;
}): Promise<BuildResult> {
if (isAppPPREnabled) {
debug(
'experimentalPPRRoutes',
JSON.stringify(Array.from(experimentalPPRRoutes))
);
}

lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);

const experimentalAllowBundling = Boolean(
Expand Down Expand Up @@ -217,20 +226,14 @@ export async function serverBuild({
}
}

const experimental = {
ppr:
requiredServerFilesManifest.config.experimental?.ppr === true ||
requiredServerFilesManifest.config.experimental?.ppr === 'incremental',
};

let appRscPrefetches: UnwrapPromise<ReturnType<typeof glob>> = {};
let appBuildTraces: UnwrapPromise<ReturnType<typeof glob>> = {};
let appDir: string | null = null;

if (appPathRoutesManifest) {
appDir = path.join(pagesDir, '../app');
appBuildTraces = await glob('**/*.js.nft.json', appDir);
appRscPrefetches = experimental.ppr
appRscPrefetches = isAppPPREnabled
? {}
: await glob(`**/*${RSC_PREFETCH_SUFFIX}`, appDir);

Expand All @@ -251,7 +254,7 @@ export async function serverBuild({
if (rewrite.src && rewrite.dest) {
rewrite.src = rewrite.src.replace(
/\/?\(\?:\/\)\?/,
`(?<rscsuff>${experimental.ppr ? '(\\.prefetch)?' : ''}\\.rsc)?(?:/)?`
`(?<rscsuff>${isAppPPREnabled ? '(\\.prefetch)?' : ''}\\.rsc)?(?:/)?`
);
let destQueryIndex = rewrite.dest.indexOf('?');

Expand Down Expand Up @@ -934,9 +937,6 @@ export async function serverBuild({
const appRouterStreamingActionLambdaGroups: LambdaGroup[] = [];

for (const group of appRouterLambdaGroups) {
if (!group.isPrerenders || group.isExperimentalPPR) {
group.isStreaming = true;
}
group.isAppRouter = true;

// We create a streaming variant of the Prerender lambda group
Expand All @@ -951,9 +951,6 @@ export async function serverBuild({
}

for (const group of appRouteHandlersLambdaGroups) {
if (!group.isPrerenders) {
group.isStreaming = true;
}
group.isAppRouter = true;
group.isAppRouteHandler = true;
}
Expand Down Expand Up @@ -984,32 +981,42 @@ export async function serverBuild({
apiLambdaGroups: apiLambdaGroups.map(group => ({
pages: group.pages,
isPrerender: group.isPrerenders,
isStreaming: group.isStreaming,
isExperimentalPPR: group.isExperimentalPPR,
pseudoLayerBytes: group.pseudoLayerBytes,
uncompressedLayerBytes: group.pseudoLayerUncompressedBytes,
})),
pageLambdaGroups: pageLambdaGroups.map(group => ({
pages: group.pages,
isPrerender: group.isPrerenders,
isStreaming: group.isStreaming,
isExperimentalPPR: group.isExperimentalPPR,
pseudoLayerBytes: group.pseudoLayerBytes,
uncompressedLayerBytes: group.pseudoLayerUncompressedBytes,
})),
appRouterLambdaGroups: appRouterLambdaGroups.map(group => ({
pages: group.pages,
isPrerender: group.isPrerenders,
isStreaming: group.isStreaming,
isExperimentalPPR: group.isExperimentalPPR,
pseudoLayerBytes: group.pseudoLayerBytes,
uncompressedLayerBytes: group.pseudoLayerUncompressedBytes,
})),
appRouterStreamingPrerenderLambdaGroups:
appRouterStreamingActionLambdaGroups.map(group => ({
pages: group.pages,
isPrerender: group.isPrerenders,
isStreaming: group.isStreaming,
isExperimentalPPR: group.isExperimentalPPR,
pseudoLayerBytes: group.pseudoLayerBytes,
uncompressedLayerBytes: group.pseudoLayerUncompressedBytes,
})),
appRouteHandlersLambdaGroups: appRouteHandlersLambdaGroups.map(
group => ({
pages: group.pages,
isPrerender: group.isPrerenders,
isStreaming: group.isStreaming,
isExperimentalPPR: group.isExperimentalPPR,
pseudoLayerBytes: group.pseudoLayerBytes,
uncompressedLayerBytes: group.pseudoLayerUncompressedBytes,
})
Expand Down Expand Up @@ -1189,15 +1196,10 @@ export async function serverBuild({

const lambda = await createLambdaFromPseudoLayers(options);

// This is a PPR lambda if it's an App Page with the PPR experimental flag
// enabled.
const isPPR =
experimental.ppr && group.isAppRouter && !group.isAppRouteHandler;

// If PPR is enabled and this is an App Page, create the non-streaming
// lambda for the page for revalidation.
let revalidate: NodejsLambda | undefined;
if (isPPR) {
if (group.isExperimentalPPR) {
if (!options.isStreaming) {
throw new Error("Invariant: PPR lambda isn't streaming");
}
Expand All @@ -1214,14 +1216,11 @@ export async function serverBuild({
// This is the name of the page, where the root is `index`.
const pageName = pageFilename.replace(/\.js$/, '');

// This is the name of the page prefixed with a `/`, where the root is
// `/index`.
const pagePath = path.posix.join('/', pageName);

// This is the routable pathname for the page, where the root is `/`.
const pagePathname = pagePath === '/index' ? '/' : pagePath;
const pagePathname = normalizePage(pageName);

let isPrerender = prerenderRoutes.has(pagePathname);
const isRoutePPREnabled = experimentalPPRRoutes.has(pagePathname);

if (!isPrerender && routesManifest?.i18n) {
isPrerender = routesManifest.i18n.locales.some(locale => {
Expand All @@ -1239,7 +1238,7 @@ export async function serverBuild({
}

// If this is a PPR page, then we should prefix the output name.
if (isPPR) {
if (isRoutePPREnabled) {
if (!revalidate) {
throw new Error("Invariant: PPR lambda isn't set");
}
Expand Down Expand Up @@ -1320,6 +1319,13 @@ export async function serverBuild({
console.timeEnd(lambdaCreationLabel);
}

if (isAppPPREnabled) {
debug(
'experimentalStreamingLambdaPaths',
JSON.stringify(Array.from(experimentalStreamingLambdaPaths))
);
}

const prerenderRoute = onPrerenderRoute({
appDir,
pagesDir,
Expand All @@ -1339,6 +1345,7 @@ export async function serverBuild({
hasPages404: routesManifest.pages404,
isCorrectNotFoundRoutes,
isEmptyAllowQueryForPrendered,
isAppPPREnabled,
});

await Promise.all(
Expand Down Expand Up @@ -1407,7 +1414,7 @@ export async function serverBuild({
bypassToken: prerenderManifest.bypassToken || '',
isServerMode: true,
dynamicMiddlewareRouteMap: middleware.dynamicRouteMap,
experimentalPPRRoutes,
isAppPPREnabled,
hasActionOutputSupport,
}).then(arr =>
localizeDynamicRoutes(
Expand Down Expand Up @@ -1589,15 +1596,15 @@ export async function serverBuild({
if (lambdas[pathname]) {
lambdas[`${pathname}.rsc`] = lambdas[pathname];

if (experimental.ppr) {
if (isAppPPREnabled) {
lambdas[`${pathname}${RSC_PREFETCH_SUFFIX}`] = lambdas[pathname];
}
}

if (edgeFunctions[pathname]) {
edgeFunctions[`${pathname}.rsc`] = edgeFunctions[pathname];

if (experimental.ppr) {
if (isAppPPREnabled) {
edgeFunctions[`${pathname}${RSC_PREFETCH_SUFFIX}`] =
edgeFunctions[pathname];
}
Expand All @@ -1616,15 +1623,15 @@ export async function serverBuild({
'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
const appNotFoundPath = path.posix.join('.', entryDirectory, '_not-found');

if (experimental.ppr && !rscPrefetchHeader) {
if (isAppPPREnabled && !rscPrefetchHeader) {
throw new Error("Invariant: cannot use PPR without 'rsc.prefetchHeader'");
}

// If we're using the Experimental Partial Prerendering, we should ensure that
// all the routes that support it (and are listed) have configured lambdas.
// This only applies to routes that do not have fallbacks enabled (these are
// routes that have `dynamicParams = false` defined.
if (experimental.ppr) {
if (isAppPPREnabled) {
for (const { srcRoute, dataRoute, experimentalPPR } of Object.values(
prerenderManifest.staticRoutes
)) {
Expand Down Expand Up @@ -1907,7 +1914,7 @@ export async function serverBuild({

...(appDir
? [
...(rscPrefetchHeader && experimental.ppr
...(rscPrefetchHeader && isAppPPREnabled
? [
{
src: `^${path.posix.join('/', entryDirectory, '/')}`,
Expand Down

0 comments on commit 4fc9f50

Please sign in to comment.