@vercel/next 4.2.13 → 4.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +58 -24
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -12718,7 +12718,6 @@ async function getPageLambdaGroups({
12718
12718
  const routeName = normalizePage(page.replace(/\.js$/, ""));
12719
12719
  const isPrerenderRoute = prerenderRoutes.has(routeName);
12720
12720
  const isExperimentalPPR = experimentalPPRRoutes?.has(routeName) ?? false;
12721
- const isStreaming = !isPrerenderRoute || isExperimentalPPR;
12722
12721
  let opts = {};
12723
12722
  if (functionsConfigManifest && functionsConfigManifest.functions[routeName]) {
12724
12723
  opts = functionsConfigManifest.functions[routeName];
@@ -12765,7 +12764,6 @@ async function getPageLambdaGroups({
12765
12764
  ...opts,
12766
12765
  isPrerenders: isPrerenderRoute,
12767
12766
  isExperimentalPPR,
12768
- isStreaming,
12769
12767
  isApiLambda: !!isApiPage(page),
12770
12768
  pseudoLayerBytes: initialPseudoLayer.pseudoLayerBytes,
12771
12769
  pseudoLayerUncompressedBytes: initialPseudoLayerUncompressed,
@@ -13059,18 +13057,18 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13059
13057
  }
13060
13058
  const isOmittedOrNotFound = isOmitted || isNotFound;
13061
13059
  let htmlFsRef = null;
13062
- let prerender;
13060
+ let postponedPrerender;
13063
13061
  if (experimentalPPR && appDir) {
13064
13062
  const htmlPath = import_path2.default.join(appDir, `${routeFileNoExt}.html`);
13065
13063
  const metaPath = import_path2.default.join(appDir, `${routeFileNoExt}.meta`);
13066
13064
  if (import_fs_extra3.default.existsSync(htmlPath) && import_fs_extra3.default.existsSync(metaPath)) {
13067
13065
  const meta = JSON.parse(await import_fs_extra3.default.readFile(metaPath, "utf8"));
13068
13066
  if ("postponed" in meta && typeof meta.postponed === "string") {
13069
- prerender = meta.postponed;
13067
+ postponedPrerender = meta.postponed;
13070
13068
  initialHeaders ??= {};
13071
13069
  initialHeaders["content-type"] = `application/x-nextjs-pre-render; state-length=${meta.postponed.length}`;
13072
13070
  const html = await import_fs_extra3.default.readFileSync(htmlPath, "utf8");
13073
- prerender += html;
13071
+ postponedPrerender += html;
13074
13072
  }
13075
13073
  }
13076
13074
  if (!dataRoute?.endsWith(".rsc")) {
@@ -13084,12 +13082,12 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13084
13082
  );
13085
13083
  }
13086
13084
  }
13087
- if (prerender) {
13085
+ if (postponedPrerender) {
13088
13086
  const contentType = initialHeaders?.["content-type"];
13089
13087
  if (!contentType) {
13090
13088
  throw new Error("Invariant: contentType can't be undefined");
13091
13089
  }
13092
- htmlFsRef = new import_build_utils.FileBlob({ contentType, data: prerender });
13090
+ htmlFsRef = new import_build_utils.FileBlob({ contentType, data: postponedPrerender });
13093
13091
  } else if (appDir && !dataRoute && !prefetchDataRoute && isAppPathRoute && !(isBlocking || isFallback)) {
13094
13092
  const contentType = initialHeaders?.["content-type"];
13095
13093
  const fsPath = import_path2.default.join(appDir, `${routeFileNoExt}.body`);
@@ -13126,7 +13124,14 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13126
13124
  isFallback || isBlocking || isNotFound && !static404Page || !dataRoute ? null : new import_build_utils.FileFsRef({
13127
13125
  fsPath: import_path2.default.join(
13128
13126
  isAppPathRoute && !isOmittedOrNotFound && appDir ? appDir : pagesDir,
13129
- `${isOmittedOrNotFound ? localePrefixed404 ? addLocaleOrDefault("/404.html", routesManifest, locale) : "/404.html" : isAppPathRoute ? prefetchDataRoute || dataRoute : routeFileNoExt + ".json"}`
13127
+ `${isOmittedOrNotFound ? localePrefixed404 ? addLocaleOrDefault("/404.html", routesManifest, locale) : "/404.html" : isAppPathRoute ? (
13128
+ // When experimental PPR is enabled, we expect that the data
13129
+ // that should be served as a part of the prerender should
13130
+ // be from the prefetch data route. If this isn't enabled
13131
+ // for ppr, the only way to get the data is from the data
13132
+ // route.
13133
+ experimentalPPR ? prefetchDataRoute : dataRoute
13134
+ ) : routeFileNoExt + ".json"}`
13130
13135
  )
13131
13136
  })
13132
13137
  );
@@ -13170,7 +13175,6 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13170
13175
  } else if (experimentalPPR) {
13171
13176
  throw new Error("Invariant: expected to find prefetch data route PPR");
13172
13177
  }
13173
- const outputPrerenderPathData = outputPathPrefetchData || outputPathData;
13174
13178
  if (isSharedLambdas) {
13175
13179
  const outputSrcPathPage = normalizeIndexOutput(
13176
13180
  import_path2.default.join(
@@ -13207,8 +13211,11 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13207
13211
  if (!canUsePreviewMode || routeKey === "/404" && !lambdas[outputPathPage]) {
13208
13212
  htmlFsRef.contentType = htmlContentType;
13209
13213
  prerenders[outputPathPage] = htmlFsRef;
13210
- if (outputPrerenderPathData) {
13211
- prerenders[outputPrerenderPathData] = jsonFsRef;
13214
+ if (outputPathPrefetchData) {
13215
+ prerenders[outputPathPrefetchData] = jsonFsRef;
13216
+ }
13217
+ if (outputPathData && !experimentalPPR) {
13218
+ prerenders[outputPathData] = jsonFsRef;
13212
13219
  }
13213
13220
  }
13214
13221
  }
@@ -13292,16 +13299,15 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13292
13299
  }
13293
13300
  } : {}
13294
13301
  });
13295
- if (outputPrerenderPathData) {
13296
- let normalizedPathData = outputPrerenderPathData;
13297
- if ((srcRoute === "/" || srcRoute == "/index") && outputPrerenderPathData.endsWith(RSC_PREFETCH_SUFFIX)) {
13298
- delete lambdas[normalizedPathData];
13299
- normalizedPathData = normalizedPathData.replace(
13300
- /([^/]+\.prefetch\.rsc)$/,
13301
- "__$1"
13302
- );
13302
+ const normalizePathData = (pathData) => {
13303
+ if ((srcRoute === "/" || srcRoute == "/index") && pathData.endsWith(RSC_PREFETCH_SUFFIX)) {
13304
+ delete lambdas[pathData];
13305
+ return pathData.replace(/([^/]+\.prefetch\.rsc)$/, "__$1");
13303
13306
  }
13304
- prerenders[normalizedPathData] = new import_build_utils.Prerender({
13307
+ return pathData;
13308
+ };
13309
+ if (outputPathData || outputPathPrefetchData) {
13310
+ const prerender = new import_build_utils.Prerender({
13305
13311
  expiration: initialRevalidate,
13306
13312
  lambda,
13307
13313
  allowQuery,
@@ -13317,13 +13323,18 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13317
13323
  ...initialHeaders,
13318
13324
  "content-type": rscContentTypeHeader,
13319
13325
  vary: rscVaryHeader,
13320
- // If it contains a pre-render, then it was postponed.
13321
- ...prerender && rscDidPostponeHeader ? { [rscDidPostponeHeader]: "1" } : {}
13326
+ ...postponedPrerender && rscDidPostponeHeader ? { [rscDidPostponeHeader]: "1" } : {}
13322
13327
  }
13323
13328
  } : {}
13324
13329
  });
13330
+ if (outputPathPrefetchData) {
13331
+ prerenders[normalizePathData(outputPathPrefetchData)] = prerender;
13332
+ }
13333
+ if (outputPathData && !experimentalPPR) {
13334
+ prerenders[normalizePathData(outputPathData)] = prerender;
13335
+ }
13325
13336
  }
13326
- if (outputPrerenderPathData?.endsWith(".json") && appDir) {
13337
+ if (outputPathData?.endsWith(".json") && appDir) {
13327
13338
  const dummyOutput = new import_build_utils.FileBlob({
13328
13339
  data: "{}",
13329
13340
  contentType: "application/json"
@@ -14464,9 +14475,10 @@ async function serverBuild({
14464
14475
  }
14465
14476
  for (const rewrite of afterFilesRewrites) {
14466
14477
  if (rewrite.src && rewrite.dest) {
14478
+ const rscSuffix = isAppPPREnabled ? `(\\.prefetch)?\\.rsc${hasActionOutputSupport ? "|\\.action" : ""}` : hasActionOutputSupport ? "(\\.action|\\.rsc)" : "\\.rsc";
14467
14479
  rewrite.src = rewrite.src.replace(
14468
14480
  /\/?\(\?:\/\)\?/,
14469
- `(?<rscsuff>${isAppPPREnabled ? "(\\.prefetch)?" : ""}\\.rsc)?(?:/)?`
14481
+ `(?<rscsuff>${rscSuffix})?(?:/)?`
14470
14482
  );
14471
14483
  let destQueryIndex = rewrite.dest.indexOf("?");
14472
14484
  if (destQueryIndex === -1) {
@@ -14980,6 +14992,9 @@ async function serverBuild({
14980
14992
  });
14981
14993
  const appRouterStreamingActionLambdaGroups = [];
14982
14994
  for (const group of appRouterLambdaGroups) {
14995
+ if (!group.isPrerenders || group.isExperimentalPPR) {
14996
+ group.isStreaming = true;
14997
+ }
14983
14998
  group.isAppRouter = true;
14984
14999
  if (hasActionOutputSupport) {
14985
15000
  appRouterStreamingActionLambdaGroups.push({
@@ -14990,6 +15005,9 @@ async function serverBuild({
14990
15005
  }
14991
15006
  }
14992
15007
  for (const group of appRouteHandlersLambdaGroups) {
15008
+ if (!group.isPrerenders) {
15009
+ group.isStreaming = true;
15010
+ }
14993
15011
  group.isAppRouter = true;
14994
15012
  group.isAppRouteHandler = true;
14995
15013
  }
@@ -15873,6 +15891,22 @@ async function serverBuild({
15873
15891
  // These need to come before handle: miss or else they are grouped
15874
15892
  // with that routing section
15875
15893
  ...afterFilesRewrites,
15894
+ // Ensure that after we normalize `afterFilesRewrites`, unmatched actions are routed to the correct handler
15895
+ // e.g. /foo/.action -> /foo.action. This should only ever match in cases where we're routing to an action handler
15896
+ // and the rewrite normalization led to something like /foo/$1$rscsuff, and $1 had no match.
15897
+ // This is meant to have parity with the .rsc handling below.
15898
+ ...hasActionOutputSupport ? [
15899
+ {
15900
+ src: `${import_path4.default.posix.join("/", entryDirectory, "/\\.action$")}`,
15901
+ dest: `${import_path4.default.posix.join("/", entryDirectory, "/index.action")}`,
15902
+ check: true
15903
+ },
15904
+ {
15905
+ src: `${import_path4.default.posix.join("/", entryDirectory, "(.+)/\\.action$")}`,
15906
+ dest: `${import_path4.default.posix.join("/", entryDirectory, "$1.action")}`,
15907
+ check: true
15908
+ }
15909
+ ] : [],
15876
15910
  // ensure non-normalized /.rsc from rewrites is handled
15877
15911
  ...appPathRoutesManifest ? [
15878
15912
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.2.13",
3
+ "version": "4.2.15",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -30,7 +30,7 @@
30
30
  "@types/semver": "6.0.0",
31
31
  "@types/text-table": "0.2.1",
32
32
  "@types/webpack-sources": "3.2.0",
33
- "@vercel/build-utils": "8.2.0",
33
+ "@vercel/build-utils": "8.2.1",
34
34
  "@vercel/routing-utils": "3.1.0",
35
35
  "async-sema": "3.0.1",
36
36
  "buffer-crc32": "0.2.13",