@vercel/next 3.5.0 → 3.5.1

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.
package/dist/index.js CHANGED
@@ -41579,6 +41579,8 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
41579
41579
  ...Object.entries(prerenderManifest.fallbackRoutes),
41580
41580
  ...Object.entries(prerenderManifest.blockingFallbackRoutes),
41581
41581
  ].forEach(([, { dataRouteRegex, dataRoute }]) => {
41582
+ if (!dataRoute || !dataRouteRegex)
41583
+ return;
41582
41584
  dataRoutes.push({
41583
41585
  // Next.js provided data route regex
41584
41586
  src: dataRouteRegex.replace(/^\^/, `^${appMountPrefixNoTrailingSlash}`),
@@ -43060,6 +43062,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43060
43062
  }
43061
43063
  }
43062
43064
  const rscHeader = routesManifest.rsc?.header?.toLowerCase() || '__rsc__';
43065
+ const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
43066
+ 'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
43063
43067
  const completeDynamicRoutes = [];
43064
43068
  if (appDir) {
43065
43069
  for (const route of dynamicRoutes) {
@@ -43270,7 +43274,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43270
43274
  },
43271
43275
  ],
43272
43276
  dest: path_1.default.posix.join('/', entryDirectory, '/index.rsc'),
43277
+ headers: { vary: rscVaryHeader },
43273
43278
  continue: true,
43279
+ override: true,
43274
43280
  },
43275
43281
  {
43276
43282
  src: `^${path_1.default.posix.join('/', entryDirectory, '/((?!.+\\.rsc).+?)(?:/)?$')}`,
@@ -43281,7 +43287,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43281
43287
  },
43282
43288
  ],
43283
43289
  dest: path_1.default.posix.join('/', entryDirectory, '/$1.rsc'),
43290
+ headers: { vary: rscVaryHeader },
43284
43291
  continue: true,
43292
+ override: true,
43285
43293
  },
43286
43294
  ]
43287
43295
  : []),
@@ -44286,7 +44294,8 @@ async function getPrerenderManifest(entryPath, outputDirectory) {
44286
44294
  return ret;
44287
44295
  }
44288
44296
  case 2:
44289
- case 3: {
44297
+ case 3:
44298
+ case 4: {
44290
44299
  const routes = Object.keys(manifest.routes);
44291
44300
  const lazyRoutes = Object.keys(manifest.dynamicRoutes);
44292
44301
  const ret = {
@@ -44303,12 +44312,20 @@ async function getPrerenderManifest(entryPath, outputDirectory) {
44303
44312
  }
44304
44313
  routes.forEach(route => {
44305
44314
  const { initialRevalidateSeconds, dataRoute, srcRoute } = manifest.routes[route];
44315
+ let initialStatus;
44316
+ let initialHeaders;
44317
+ if (manifest.version === 4) {
44318
+ initialStatus = manifest.routes[route].initialStatus;
44319
+ initialHeaders = manifest.routes[route].initialHeaders;
44320
+ }
44306
44321
  ret.staticRoutes[route] = {
44307
44322
  initialRevalidate: initialRevalidateSeconds === false
44308
44323
  ? false
44309
44324
  : Math.max(1, initialRevalidateSeconds),
44310
44325
  dataRoute,
44311
44326
  srcRoute,
44327
+ initialStatus,
44328
+ initialHeaders,
44312
44329
  };
44313
44330
  });
44314
44331
  lazyRoutes.forEach(lazyRoute => {
@@ -44642,7 +44659,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
44642
44659
  const pr = prerenderManifest.staticRoutes[routeKey];
44643
44660
  const { initialRevalidate, srcRoute, dataRoute } = pr;
44644
44661
  const route = srcRoute || routeKey;
44645
- const isAppPathRoute = appDir && dataRoute?.endsWith('.rsc');
44662
+ const isAppPathRoute = appDir && (!dataRoute || dataRoute?.endsWith('.rsc'));
44646
44663
  const routeNoLocale = routesManifest?.i18n
44647
44664
  ? normalizeLocalePath(routeKey, routesManifest.i18n.locales).pathname
44648
44665
  : routeKey;
@@ -44724,6 +44741,8 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44724
44741
  let initialRevalidate;
44725
44742
  let srcRoute;
44726
44743
  let dataRoute;
44744
+ let initialStatus;
44745
+ let initialHeaders;
44727
44746
  if (isFallback || isBlocking) {
44728
44747
  const pr = isFallback
44729
44748
  ? prerenderManifest.fallbackRoutes[routeKey]
@@ -44747,32 +44766,49 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44747
44766
  }
44748
44767
  else {
44749
44768
  const pr = prerenderManifest.staticRoutes[routeKey];
44750
- ({ initialRevalidate, srcRoute, dataRoute } = pr);
44769
+ ({
44770
+ initialRevalidate,
44771
+ srcRoute,
44772
+ dataRoute,
44773
+ initialHeaders,
44774
+ initialStatus,
44775
+ } = pr);
44751
44776
  }
44752
44777
  let isAppPathRoute = false;
44753
44778
  // TODO: leverage manifest to determine app paths more accurately
44754
- if (appDir && srcRoute && dataRoute.endsWith('.rsc')) {
44779
+ if (appDir && srcRoute && (!dataRoute || dataRoute?.endsWith('.rsc'))) {
44755
44780
  isAppPathRoute = true;
44756
44781
  }
44757
44782
  const isOmittedOrNotFound = isOmitted || isNotFound;
44758
- const htmlFsRef = isBlocking || (isNotFound && !static404Page)
44759
- ? // Blocking pages do not have an HTML fallback
44760
- null
44761
- : new build_utils_1.FileFsRef({
44762
- fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
44763
- ? appDir
44764
- : pagesDir, isFallback
44765
- ? // Fallback pages have a special file.
44766
- addLocaleOrDefault(prerenderManifest.fallbackRoutes[routeKey].fallback, routesManifest, locale)
44767
- : // Otherwise, the route itself should exist as a static HTML
44768
- // file.
44769
- `${isOmittedOrNotFound
44770
- ? addLocaleOrDefault('/404', routesManifest, locale)
44771
- : routeFileNoExt}.html`),
44783
+ let htmlFsRef;
44784
+ if (appDir && !dataRoute && isAppPathRoute && !(isBlocking || isFallback)) {
44785
+ const contentType = initialHeaders?.['content-type'];
44786
+ htmlFsRef = new build_utils_1.FileFsRef({
44787
+ fsPath: path_1.default.join(appDir, `${routeFileNoExt}.body`),
44788
+ contentType: contentType || 'text/html;charset=utf-8',
44772
44789
  });
44790
+ }
44791
+ else {
44792
+ htmlFsRef =
44793
+ isBlocking || (isNotFound && !static404Page)
44794
+ ? // Blocking pages do not have an HTML fallback
44795
+ null
44796
+ : new build_utils_1.FileFsRef({
44797
+ fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
44798
+ ? appDir
44799
+ : pagesDir, isFallback
44800
+ ? // Fallback pages have a special file.
44801
+ addLocaleOrDefault(prerenderManifest.fallbackRoutes[routeKey].fallback, routesManifest, locale)
44802
+ : // Otherwise, the route itself should exist as a static HTML
44803
+ // file.
44804
+ `${isOmittedOrNotFound
44805
+ ? addLocaleOrDefault('/404', routesManifest, locale)
44806
+ : routeFileNoExt}.html`),
44807
+ });
44808
+ }
44773
44809
  const jsonFsRef =
44774
44810
  // JSON data does not exist for fallback or blocking pages
44775
- isFallback || isBlocking || (isNotFound && !static404Page)
44811
+ isFallback || isBlocking || (isNotFound && !static404Page) || !dataRoute
44776
44812
  ? null
44777
44813
  : new build_utils_1.FileFsRef({
44778
44814
  fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
@@ -44798,13 +44834,16 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44798
44834
  }
44799
44835
  const outputPathPageOrig = path_1.default.posix.join(entryDirectory, origRouteFileNoExt);
44800
44836
  let lambda;
44801
- let outputPathData = path_1.default.posix.join(entryDirectory, dataRoute);
44802
- if (nonDynamicSsg || isFallback || isOmitted) {
44803
- outputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`),
44804
- // ensure we escape "$" correctly while replacing as "$" is a special
44805
- // character, we need to do double escaping as first is for the initial
44806
- // replace on the routeFile and then the second on the outputPath
44807
- `${routeFileNoExt.replace(/\$/g, '$$$$')}.json`);
44837
+ let outputPathData = null;
44838
+ if (dataRoute) {
44839
+ outputPathData = path_1.default.posix.join(entryDirectory, dataRoute);
44840
+ if (nonDynamicSsg || isFallback || isOmitted) {
44841
+ outputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`),
44842
+ // ensure we escape "$" correctly while replacing as "$" is a special
44843
+ // character, we need to do double escaping as first is for the initial
44844
+ // replace on the routeFile and then the second on the outputPath
44845
+ `${routeFileNoExt.replace(/\$/g, '$$$$')}.json`);
44846
+ }
44808
44847
  }
44809
44848
  if (isSharedLambdas) {
44810
44849
  const outputSrcPathPage = normalizeIndexOutput(path_1.default.join('/', srcRoute == null
@@ -44823,7 +44862,7 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44823
44862
  if (htmlFsRef == null || jsonFsRef == null) {
44824
44863
  throw new build_utils_1.NowBuildError({
44825
44864
  code: 'NEXT_HTMLFSREF_JSONFSREF',
44826
- message: 'invariant: htmlFsRef != null && jsonFsRef != null',
44865
+ message: `invariant: htmlFsRef != null && jsonFsRef != null ${routeFileNoExt}`,
44827
44866
  });
44828
44867
  }
44829
44868
  // if preview mode/On-Demand ISR can't be leveraged
@@ -44832,7 +44871,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44832
44871
  (routeKey === '/404' && !lambdas[outputPathPage])) {
44833
44872
  htmlFsRef.contentType = _1.htmlContentType;
44834
44873
  prerenders[outputPathPage] = htmlFsRef;
44835
- prerenders[outputPathData] = jsonFsRef;
44874
+ if (outputPathData) {
44875
+ prerenders[outputPathData] = jsonFsRef;
44876
+ }
44836
44877
  }
44837
44878
  }
44838
44879
  const isNotFoundPreview = isCorrectNotFoundRoutes &&
@@ -44886,9 +44927,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44886
44927
  allowQuery = [];
44887
44928
  }
44888
44929
  }
44889
- const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
44890
- '__rsc__, __next_router_state_tree__, __next_router_prefetch__';
44891
- const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || 'application/octet-stream';
44930
+ const rscEnabled = !!routesManifest?.rsc;
44931
+ const rscVaryHeader = routesManifest?.rsc?.varyHeader || 'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
44932
+ const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || 'text/x-component';
44892
44933
  prerenders[outputPathPage] = new build_utils_1.Prerender({
44893
44934
  expiration: initialRevalidate,
44894
44935
  lambda,
@@ -44896,59 +44937,66 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
44896
44937
  fallback: htmlFsRef,
44897
44938
  group: prerenderGroup,
44898
44939
  bypassToken: prerenderManifest.bypassToken,
44940
+ initialStatus,
44941
+ initialHeaders,
44899
44942
  ...(isNotFound
44900
44943
  ? {
44901
44944
  initialStatus: 404,
44902
44945
  }
44903
44946
  : {}),
44904
- ...(isAppPathRoute
44947
+ ...(rscEnabled
44905
44948
  ? {
44906
44949
  initialHeaders: {
44950
+ ...initialHeaders,
44907
44951
  vary: rscVaryHeader,
44908
44952
  },
44909
44953
  }
44910
44954
  : {}),
44911
44955
  });
44912
- prerenders[outputPathData] = new build_utils_1.Prerender({
44913
- expiration: initialRevalidate,
44914
- lambda,
44915
- allowQuery,
44916
- fallback: jsonFsRef,
44917
- group: prerenderGroup,
44918
- bypassToken: prerenderManifest.bypassToken,
44919
- ...(isNotFound
44920
- ? {
44921
- initialStatus: 404,
44922
- }
44923
- : {}),
44924
- ...(isAppPathRoute
44925
- ? {
44926
- initialHeaders: {
44927
- 'content-type': rscContentTypeHeader,
44928
- vary: rscVaryHeader,
44929
- },
44930
- }
44931
- : {}),
44932
- });
44956
+ if (outputPathData) {
44957
+ prerenders[outputPathData] = new build_utils_1.Prerender({
44958
+ expiration: initialRevalidate,
44959
+ lambda,
44960
+ allowQuery,
44961
+ fallback: jsonFsRef,
44962
+ group: prerenderGroup,
44963
+ bypassToken: prerenderManifest.bypassToken,
44964
+ ...(isNotFound
44965
+ ? {
44966
+ initialStatus: 404,
44967
+ }
44968
+ : {}),
44969
+ ...(rscEnabled
44970
+ ? {
44971
+ initialHeaders: {
44972
+ 'content-type': rscContentTypeHeader,
44973
+ vary: rscVaryHeader,
44974
+ },
44975
+ }
44976
+ : {}),
44977
+ });
44978
+ }
44933
44979
  ++prerenderGroup;
44934
44980
  if (routesManifest?.i18n && isBlocking) {
44935
44981
  for (const locale of routesManifest.i18n.locales) {
44936
44982
  const localeRouteFileNoExt = addLocaleOrDefault(routeFileNoExt, routesManifest, locale);
44937
44983
  const localeOutputPathPage = normalizeIndexOutput(path_1.default.posix.join(entryDirectory, localeRouteFileNoExt), isServerMode);
44938
- const localeOutputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`), `${localeRouteFileNoExt}${localeRouteFileNoExt !== origRouteFileNoExt &&
44939
- origRouteFileNoExt === '/index'
44940
- ? '/index'
44941
- : ''}.json`);
44942
44984
  const origPrerenderPage = prerenders[outputPathPage];
44943
- const origPrerenderData = prerenders[outputPathData];
44944
44985
  prerenders[localeOutputPathPage] = {
44945
44986
  ...origPrerenderPage,
44946
44987
  group: prerenderGroup,
44947
44988
  };
44948
- prerenders[localeOutputPathData] = {
44949
- ...origPrerenderData,
44950
- group: prerenderGroup,
44951
- };
44989
+ if (outputPathData) {
44990
+ const localeOutputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`), `${localeRouteFileNoExt}${localeRouteFileNoExt !== origRouteFileNoExt &&
44991
+ origRouteFileNoExt === '/index'
44992
+ ? '/index'
44993
+ : ''}.json`);
44994
+ const origPrerenderData = prerenders[outputPathData];
44995
+ prerenders[localeOutputPathData] = {
44996
+ ...origPrerenderData,
44997
+ group: prerenderGroup,
44998
+ };
44999
+ }
44952
45000
  ++prerenderGroup;
44953
45001
  }
44954
45002
  }
@@ -45180,9 +45228,11 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
45180
45228
  if (shortPath.startsWith('pages/')) {
45181
45229
  shortPath = shortPath.replace(/^pages\//, '');
45182
45230
  }
45183
- else if (shortPath.startsWith('app/') && shortPath.endsWith('/page')) {
45231
+ else if (shortPath.startsWith('app/') &&
45232
+ (shortPath.endsWith('/page') || shortPath.endsWith('/route'))) {
45184
45233
  shortPath =
45185
- shortPath.replace(/^app\//, '').replace(/(^|\/)page$/, '') || 'index';
45234
+ shortPath.replace(/^app\//, '').replace(/(^|\/)(page|route)$/, '') ||
45235
+ 'index';
45186
45236
  }
45187
45237
  if (routesManifest?.basePath) {
45188
45238
  shortPath = path_1.default.posix
@@ -674,6 +674,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
674
674
  }
675
675
  }
676
676
  const rscHeader = routesManifest.rsc?.header?.toLowerCase() || '__rsc__';
677
+ const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
678
+ 'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
677
679
  const completeDynamicRoutes = [];
678
680
  if (appDir) {
679
681
  for (const route of dynamicRoutes) {
@@ -884,7 +886,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
884
886
  },
885
887
  ],
886
888
  dest: path_1.default.posix.join('/', entryDirectory, '/index.rsc'),
889
+ headers: { vary: rscVaryHeader },
887
890
  continue: true,
891
+ override: true,
888
892
  },
889
893
  {
890
894
  src: `^${path_1.default.posix.join('/', entryDirectory, '/((?!.+\\.rsc).+?)(?:/)?$')}`,
@@ -895,7 +899,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
895
899
  },
896
900
  ],
897
901
  dest: path_1.default.posix.join('/', entryDirectory, '/$1.rsc'),
902
+ headers: { vary: rscVaryHeader },
898
903
  continue: true,
904
+ override: true,
899
905
  },
900
906
  ]
901
907
  : []),
package/dist/utils.js CHANGED
@@ -658,7 +658,8 @@ async function getPrerenderManifest(entryPath, outputDirectory) {
658
658
  return ret;
659
659
  }
660
660
  case 2:
661
- case 3: {
661
+ case 3:
662
+ case 4: {
662
663
  const routes = Object.keys(manifest.routes);
663
664
  const lazyRoutes = Object.keys(manifest.dynamicRoutes);
664
665
  const ret = {
@@ -675,12 +676,20 @@ async function getPrerenderManifest(entryPath, outputDirectory) {
675
676
  }
676
677
  routes.forEach(route => {
677
678
  const { initialRevalidateSeconds, dataRoute, srcRoute } = manifest.routes[route];
679
+ let initialStatus;
680
+ let initialHeaders;
681
+ if (manifest.version === 4) {
682
+ initialStatus = manifest.routes[route].initialStatus;
683
+ initialHeaders = manifest.routes[route].initialHeaders;
684
+ }
678
685
  ret.staticRoutes[route] = {
679
686
  initialRevalidate: initialRevalidateSeconds === false
680
687
  ? false
681
688
  : Math.max(1, initialRevalidateSeconds),
682
689
  dataRoute,
683
690
  srcRoute,
691
+ initialStatus,
692
+ initialHeaders,
684
693
  };
685
694
  });
686
695
  lazyRoutes.forEach(lazyRoute => {
@@ -1014,7 +1023,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
1014
1023
  const pr = prerenderManifest.staticRoutes[routeKey];
1015
1024
  const { initialRevalidate, srcRoute, dataRoute } = pr;
1016
1025
  const route = srcRoute || routeKey;
1017
- const isAppPathRoute = appDir && dataRoute?.endsWith('.rsc');
1026
+ const isAppPathRoute = appDir && (!dataRoute || dataRoute?.endsWith('.rsc'));
1018
1027
  const routeNoLocale = routesManifest?.i18n
1019
1028
  ? normalizeLocalePath(routeKey, routesManifest.i18n.locales).pathname
1020
1029
  : routeKey;
@@ -1096,6 +1105,8 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1096
1105
  let initialRevalidate;
1097
1106
  let srcRoute;
1098
1107
  let dataRoute;
1108
+ let initialStatus;
1109
+ let initialHeaders;
1099
1110
  if (isFallback || isBlocking) {
1100
1111
  const pr = isFallback
1101
1112
  ? prerenderManifest.fallbackRoutes[routeKey]
@@ -1119,32 +1130,49 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1119
1130
  }
1120
1131
  else {
1121
1132
  const pr = prerenderManifest.staticRoutes[routeKey];
1122
- ({ initialRevalidate, srcRoute, dataRoute } = pr);
1133
+ ({
1134
+ initialRevalidate,
1135
+ srcRoute,
1136
+ dataRoute,
1137
+ initialHeaders,
1138
+ initialStatus,
1139
+ } = pr);
1123
1140
  }
1124
1141
  let isAppPathRoute = false;
1125
1142
  // TODO: leverage manifest to determine app paths more accurately
1126
- if (appDir && srcRoute && dataRoute.endsWith('.rsc')) {
1143
+ if (appDir && srcRoute && (!dataRoute || dataRoute?.endsWith('.rsc'))) {
1127
1144
  isAppPathRoute = true;
1128
1145
  }
1129
1146
  const isOmittedOrNotFound = isOmitted || isNotFound;
1130
- const htmlFsRef = isBlocking || (isNotFound && !static404Page)
1131
- ? // Blocking pages do not have an HTML fallback
1132
- null
1133
- : new build_utils_1.FileFsRef({
1134
- fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
1135
- ? appDir
1136
- : pagesDir, isFallback
1137
- ? // Fallback pages have a special file.
1138
- addLocaleOrDefault(prerenderManifest.fallbackRoutes[routeKey].fallback, routesManifest, locale)
1139
- : // Otherwise, the route itself should exist as a static HTML
1140
- // file.
1141
- `${isOmittedOrNotFound
1142
- ? addLocaleOrDefault('/404', routesManifest, locale)
1143
- : routeFileNoExt}.html`),
1147
+ let htmlFsRef;
1148
+ if (appDir && !dataRoute && isAppPathRoute && !(isBlocking || isFallback)) {
1149
+ const contentType = initialHeaders?.['content-type'];
1150
+ htmlFsRef = new build_utils_1.FileFsRef({
1151
+ fsPath: path_1.default.join(appDir, `${routeFileNoExt}.body`),
1152
+ contentType: contentType || 'text/html;charset=utf-8',
1144
1153
  });
1154
+ }
1155
+ else {
1156
+ htmlFsRef =
1157
+ isBlocking || (isNotFound && !static404Page)
1158
+ ? // Blocking pages do not have an HTML fallback
1159
+ null
1160
+ : new build_utils_1.FileFsRef({
1161
+ fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
1162
+ ? appDir
1163
+ : pagesDir, isFallback
1164
+ ? // Fallback pages have a special file.
1165
+ addLocaleOrDefault(prerenderManifest.fallbackRoutes[routeKey].fallback, routesManifest, locale)
1166
+ : // Otherwise, the route itself should exist as a static HTML
1167
+ // file.
1168
+ `${isOmittedOrNotFound
1169
+ ? addLocaleOrDefault('/404', routesManifest, locale)
1170
+ : routeFileNoExt}.html`),
1171
+ });
1172
+ }
1145
1173
  const jsonFsRef =
1146
1174
  // JSON data does not exist for fallback or blocking pages
1147
- isFallback || isBlocking || (isNotFound && !static404Page)
1175
+ isFallback || isBlocking || (isNotFound && !static404Page) || !dataRoute
1148
1176
  ? null
1149
1177
  : new build_utils_1.FileFsRef({
1150
1178
  fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
@@ -1170,13 +1198,16 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1170
1198
  }
1171
1199
  const outputPathPageOrig = path_1.default.posix.join(entryDirectory, origRouteFileNoExt);
1172
1200
  let lambda;
1173
- let outputPathData = path_1.default.posix.join(entryDirectory, dataRoute);
1174
- if (nonDynamicSsg || isFallback || isOmitted) {
1175
- outputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`),
1176
- // ensure we escape "$" correctly while replacing as "$" is a special
1177
- // character, we need to do double escaping as first is for the initial
1178
- // replace on the routeFile and then the second on the outputPath
1179
- `${routeFileNoExt.replace(/\$/g, '$$$$')}.json`);
1201
+ let outputPathData = null;
1202
+ if (dataRoute) {
1203
+ outputPathData = path_1.default.posix.join(entryDirectory, dataRoute);
1204
+ if (nonDynamicSsg || isFallback || isOmitted) {
1205
+ outputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`),
1206
+ // ensure we escape "$" correctly while replacing as "$" is a special
1207
+ // character, we need to do double escaping as first is for the initial
1208
+ // replace on the routeFile and then the second on the outputPath
1209
+ `${routeFileNoExt.replace(/\$/g, '$$$$')}.json`);
1210
+ }
1180
1211
  }
1181
1212
  if (isSharedLambdas) {
1182
1213
  const outputSrcPathPage = normalizeIndexOutput(path_1.default.join('/', srcRoute == null
@@ -1195,7 +1226,7 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1195
1226
  if (htmlFsRef == null || jsonFsRef == null) {
1196
1227
  throw new build_utils_1.NowBuildError({
1197
1228
  code: 'NEXT_HTMLFSREF_JSONFSREF',
1198
- message: 'invariant: htmlFsRef != null && jsonFsRef != null',
1229
+ message: `invariant: htmlFsRef != null && jsonFsRef != null ${routeFileNoExt}`,
1199
1230
  });
1200
1231
  }
1201
1232
  // if preview mode/On-Demand ISR can't be leveraged
@@ -1204,7 +1235,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1204
1235
  (routeKey === '/404' && !lambdas[outputPathPage])) {
1205
1236
  htmlFsRef.contentType = _1.htmlContentType;
1206
1237
  prerenders[outputPathPage] = htmlFsRef;
1207
- prerenders[outputPathData] = jsonFsRef;
1238
+ if (outputPathData) {
1239
+ prerenders[outputPathData] = jsonFsRef;
1240
+ }
1208
1241
  }
1209
1242
  }
1210
1243
  const isNotFoundPreview = isCorrectNotFoundRoutes &&
@@ -1258,9 +1291,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1258
1291
  allowQuery = [];
1259
1292
  }
1260
1293
  }
1261
- const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
1262
- '__rsc__, __next_router_state_tree__, __next_router_prefetch__';
1263
- const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || 'application/octet-stream';
1294
+ const rscEnabled = !!routesManifest?.rsc;
1295
+ const rscVaryHeader = routesManifest?.rsc?.varyHeader || 'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
1296
+ const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || 'text/x-component';
1264
1297
  prerenders[outputPathPage] = new build_utils_1.Prerender({
1265
1298
  expiration: initialRevalidate,
1266
1299
  lambda,
@@ -1268,59 +1301,66 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1268
1301
  fallback: htmlFsRef,
1269
1302
  group: prerenderGroup,
1270
1303
  bypassToken: prerenderManifest.bypassToken,
1304
+ initialStatus,
1305
+ initialHeaders,
1271
1306
  ...(isNotFound
1272
1307
  ? {
1273
1308
  initialStatus: 404,
1274
1309
  }
1275
1310
  : {}),
1276
- ...(isAppPathRoute
1277
- ? {
1278
- initialHeaders: {
1279
- vary: rscVaryHeader,
1280
- },
1281
- }
1282
- : {}),
1283
- });
1284
- prerenders[outputPathData] = new build_utils_1.Prerender({
1285
- expiration: initialRevalidate,
1286
- lambda,
1287
- allowQuery,
1288
- fallback: jsonFsRef,
1289
- group: prerenderGroup,
1290
- bypassToken: prerenderManifest.bypassToken,
1291
- ...(isNotFound
1292
- ? {
1293
- initialStatus: 404,
1294
- }
1295
- : {}),
1296
- ...(isAppPathRoute
1311
+ ...(rscEnabled
1297
1312
  ? {
1298
1313
  initialHeaders: {
1299
- 'content-type': rscContentTypeHeader,
1314
+ ...initialHeaders,
1300
1315
  vary: rscVaryHeader,
1301
1316
  },
1302
1317
  }
1303
1318
  : {}),
1304
1319
  });
1320
+ if (outputPathData) {
1321
+ prerenders[outputPathData] = new build_utils_1.Prerender({
1322
+ expiration: initialRevalidate,
1323
+ lambda,
1324
+ allowQuery,
1325
+ fallback: jsonFsRef,
1326
+ group: prerenderGroup,
1327
+ bypassToken: prerenderManifest.bypassToken,
1328
+ ...(isNotFound
1329
+ ? {
1330
+ initialStatus: 404,
1331
+ }
1332
+ : {}),
1333
+ ...(rscEnabled
1334
+ ? {
1335
+ initialHeaders: {
1336
+ 'content-type': rscContentTypeHeader,
1337
+ vary: rscVaryHeader,
1338
+ },
1339
+ }
1340
+ : {}),
1341
+ });
1342
+ }
1305
1343
  ++prerenderGroup;
1306
1344
  if (routesManifest?.i18n && isBlocking) {
1307
1345
  for (const locale of routesManifest.i18n.locales) {
1308
1346
  const localeRouteFileNoExt = addLocaleOrDefault(routeFileNoExt, routesManifest, locale);
1309
1347
  const localeOutputPathPage = normalizeIndexOutput(path_1.default.posix.join(entryDirectory, localeRouteFileNoExt), isServerMode);
1310
- const localeOutputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`), `${localeRouteFileNoExt}${localeRouteFileNoExt !== origRouteFileNoExt &&
1311
- origRouteFileNoExt === '/index'
1312
- ? '/index'
1313
- : ''}.json`);
1314
1348
  const origPrerenderPage = prerenders[outputPathPage];
1315
- const origPrerenderData = prerenders[outputPathData];
1316
1349
  prerenders[localeOutputPathPage] = {
1317
1350
  ...origPrerenderPage,
1318
1351
  group: prerenderGroup,
1319
1352
  };
1320
- prerenders[localeOutputPathData] = {
1321
- ...origPrerenderData,
1322
- group: prerenderGroup,
1323
- };
1353
+ if (outputPathData) {
1354
+ const localeOutputPathData = outputPathData.replace(new RegExp(`${(0, escape_string_regexp_1.default)(origRouteFileNoExt)}.json$`), `${localeRouteFileNoExt}${localeRouteFileNoExt !== origRouteFileNoExt &&
1355
+ origRouteFileNoExt === '/index'
1356
+ ? '/index'
1357
+ : ''}.json`);
1358
+ const origPrerenderData = prerenders[outputPathData];
1359
+ prerenders[localeOutputPathData] = {
1360
+ ...origPrerenderData,
1361
+ group: prerenderGroup,
1362
+ };
1363
+ }
1324
1364
  ++prerenderGroup;
1325
1365
  }
1326
1366
  }
@@ -1552,9 +1592,11 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1552
1592
  if (shortPath.startsWith('pages/')) {
1553
1593
  shortPath = shortPath.replace(/^pages\//, '');
1554
1594
  }
1555
- else if (shortPath.startsWith('app/') && shortPath.endsWith('/page')) {
1595
+ else if (shortPath.startsWith('app/') &&
1596
+ (shortPath.endsWith('/page') || shortPath.endsWith('/route'))) {
1556
1597
  shortPath =
1557
- shortPath.replace(/^app\//, '').replace(/(^|\/)page$/, '') || 'index';
1598
+ shortPath.replace(/^app\//, '').replace(/(^|\/)(page|route)$/, '') ||
1599
+ 'index';
1558
1600
  }
1559
1601
  if (routesManifest?.basePath) {
1560
1602
  shortPath = path_1.default.posix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -71,5 +71,5 @@
71
71
  "typescript": "4.5.2",
72
72
  "webpack-sources": "3.2.3"
73
73
  },
74
- "gitHead": "70a53515bd12202f895c369504e2d5be6c9469f4"
74
+ "gitHead": "2fd33152219e7a2485b85b698e339c9c5cee23cf"
75
75
  }