@vercel/next 3.1.18 → 3.1.21

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
@@ -42910,6 +42910,10 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
42910
42910
  ? // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
42911
42911
  path_1.default.join('/', routesManifest?.i18n.defaultLocale, '/404')
42912
42912
  : '/404']?.initialRevalidate === 'number';
42913
+ const hasIsr500Page = typeof prerenderManifest.staticRoutes[routesManifest?.i18n
42914
+ ? // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
42915
+ path_1.default.join('/', routesManifest?.i18n.defaultLocale, '/500')
42916
+ : '/500']?.initialRevalidate === 'number';
42913
42917
  const wildcardConfig = routesManifest?.i18n?.domains && routesManifest.i18n.domains.length > 0
42914
42918
  ? routesManifest.i18n.domains.map(item => {
42915
42919
  return {
@@ -43287,7 +43291,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
43287
43291
  nextFiles['next.config.js'] = filesAfterBuild['next.config.js'];
43288
43292
  }
43289
43293
  const pagesDir = path_1.default.join(entryPath, outputDirectory, 'server', 'static', buildId, 'pages');
43290
- const pages = await getServerlessPages({
43294
+ const { pages } = await getServerlessPages({
43291
43295
  pagesDir,
43292
43296
  entryPath,
43293
43297
  outputDirectory,
@@ -43337,10 +43341,12 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
43337
43341
  else {
43338
43342
  (0, build_utils_1.debug)('Preparing serverless function files...');
43339
43343
  const pagesDir = path_1.default.join(entryPath, outputDirectory, isServerMode ? 'server' : 'serverless', 'pages');
43340
- const pages = await getServerlessPages({
43344
+ const appPathRoutesManifest = await (0, fs_extra_1.readJSON)(path_1.default.join(entryPath, outputDirectory, 'app-path-routes-manifest.json')).catch(() => null);
43345
+ const { pages, appPaths: lambdaAppPaths } = await getServerlessPages({
43341
43346
  pagesDir,
43342
43347
  entryPath,
43343
43348
  outputDirectory,
43349
+ appPathRoutesManifest,
43344
43350
  });
43345
43351
  const isApiPage = (page) => page
43346
43352
  .replace(/\\/g, '/')
@@ -43470,10 +43476,12 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
43470
43476
  config,
43471
43477
  nextVersion,
43472
43478
  trailingSlash,
43479
+ appPathRoutesManifest,
43473
43480
  dynamicPages,
43474
43481
  canUsePreviewMode,
43475
43482
  staticPages,
43476
43483
  lambdaPages: pages,
43484
+ lambdaAppPaths,
43477
43485
  omittedPrerenderRoutes,
43478
43486
  isCorrectLocaleAPIRoutes,
43479
43487
  pagesDir,
@@ -43501,6 +43509,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
43501
43509
  requiredServerFilesManifest,
43502
43510
  privateOutputs,
43503
43511
  hasIsr404Page,
43512
+ hasIsr500Page,
43504
43513
  });
43505
43514
  }
43506
43515
  // > 1 because _error is a lambda but isn't used if a static 404 is available
@@ -44438,15 +44447,30 @@ const prepareCache = async ({ workPath, repoRootPath, entrypoint, config = {}, }
44438
44447
  };
44439
44448
  exports.prepareCache = prepareCache;
44440
44449
  async function getServerlessPages(params) {
44441
- const [pages, middlewareManifest] = await Promise.all([
44450
+ const [pages, appPaths, middlewareManifest] = await Promise.all([
44442
44451
  (0, build_utils_1.glob)('**/!(_middleware).js', params.pagesDir),
44452
+ params.appPathRoutesManifest
44453
+ ? (0, build_utils_1.glob)('**/page.js', path_1.default.join(params.pagesDir, '../app'))
44454
+ : Promise.resolve({}),
44443
44455
  (0, utils_1.getMiddlewareManifest)(params.entryPath, params.outputDirectory),
44444
44456
  ]);
44457
+ const normalizedAppPaths = {};
44458
+ if (params.appPathRoutesManifest) {
44459
+ for (const [entry, normalizedEntry] of Object.entries(params.appPathRoutesManifest)) {
44460
+ const normalizedPath = `${path_1.default.join('.', normalizedEntry)}.js`;
44461
+ const globPath = `${path_1.default.join('.', entry)}.js`;
44462
+ if (appPaths[globPath]) {
44463
+ normalizedAppPaths[normalizedPath] = appPaths[globPath];
44464
+ }
44465
+ }
44466
+ }
44445
44467
  // Edge Functions do not consider as Serverless Functions
44446
44468
  for (const edgeFunctionFile of Object.keys(middlewareManifest?.functions ?? {})) {
44447
- delete pages[edgeFunctionFile.slice(1) + '.js'];
44469
+ const edgePath = edgeFunctionFile.slice(1) + '.js';
44470
+ delete normalizedAppPaths[edgePath];
44471
+ delete pages[edgePath];
44448
44472
  }
44449
- return pages;
44473
+ return { pages, appPaths: normalizedAppPaths };
44450
44474
  }
44451
44475
 
44452
44476
 
@@ -44825,13 +44849,20 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
44825
44849
  const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
44826
44850
  const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
44827
44851
  const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
44828
- async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, trailingSlash, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
44852
+ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
44853
+ lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
44829
44854
  const lambdas = {};
44830
44855
  const prerenders = {};
44831
44856
  const lambdaPageKeys = Object.keys(lambdaPages);
44832
44857
  const internalPages = ['_app.js', '_error.js', '_document.js'];
44833
44858
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
44834
44859
  const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
44860
+ let appBuildTraces = {};
44861
+ let appDir = null;
44862
+ if (appPathRoutesManifest) {
44863
+ appDir = path_1.default.join(pagesDir, '../app');
44864
+ appBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', appDir);
44865
+ }
44835
44866
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
44836
44867
  const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
44837
44868
  const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
@@ -45068,9 +45099,21 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45068
45099
  const compressedPages = {};
45069
45100
  const mergedPageKeys = [...nonApiPages, ...apiPages, ...internalPages];
45070
45101
  const traceCache = {};
45102
+ const getOriginalPagePath = (page) => {
45103
+ let originalPagePath = page;
45104
+ if (appDir && lambdaAppPaths[page]) {
45105
+ const { fsPath } = lambdaAppPaths[page];
45106
+ originalPagePath = path_1.default.relative(appDir, fsPath);
45107
+ }
45108
+ return originalPagePath;
45109
+ };
45110
+ const getBuildTraceFile = (page) => {
45111
+ return (pageBuildTraces[page + '.nft.json'] ||
45112
+ appBuildTraces[page + '.nft.json']);
45113
+ };
45071
45114
  const pathsToTrace = mergedPageKeys
45072
45115
  .map(page => {
45073
- if (!pageBuildTraces[page + '.nft.json']) {
45116
+ if (!getBuildTraceFile(page)) {
45074
45117
  return lambdaPages[page].fsPath;
45075
45118
  }
45076
45119
  })
@@ -45088,13 +45131,31 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45088
45131
  }
45089
45132
  for (const page of mergedPageKeys) {
45090
45133
  const tracedFiles = {};
45091
- const pageBuildTrace = pageBuildTraces[page + '.nft.json'];
45134
+ const originalPagePath = getOriginalPagePath(page);
45135
+ const pageBuildTrace = getBuildTraceFile(originalPagePath);
45092
45136
  let fileList;
45093
45137
  let reasons;
45094
45138
  if (pageBuildTrace) {
45095
45139
  const { files } = JSON.parse(await fs_extra_1.default.readFile(pageBuildTrace.fsPath, 'utf8'));
45140
+ // TODO: this will be moved to a separate worker in the future
45141
+ // although currently this is needed in the lambda
45142
+ const isAppPath = appDir && lambdaAppPaths[page];
45143
+ const serverComponentFile = isAppPath
45144
+ ? pageBuildTrace.fsPath.replace(/\.js\.nft\.json$/, '.__sc_client__.js')
45145
+ : null;
45146
+ if (serverComponentFile && (await fs_extra_1.default.pathExists(serverComponentFile))) {
45147
+ files.push(path_1.default.relative(path_1.default.dirname(pageBuildTrace.fsPath), serverComponentFile));
45148
+ try {
45149
+ const scTrace = JSON.parse(await fs_extra_1.default.readFile(`${serverComponentFile}.nft.json`, 'utf8'));
45150
+ scTrace.files.forEach((file) => files.push(file));
45151
+ }
45152
+ catch (err) {
45153
+ /* non-fatal for now */
45154
+ }
45155
+ }
45096
45156
  fileList = [];
45097
- const pageDir = path_1.default.dirname(path_1.default.join(pagesDir, page));
45157
+ const curPagesDir = isAppPath && appDir ? appDir : pagesDir;
45158
+ const pageDir = path_1.default.dirname(path_1.default.join(curPagesDir, originalPagePath));
45098
45159
  const normalizedBaseDir = `${baseDir}${baseDir.endsWith('/') ? '' : '/'}`;
45099
45160
  files.forEach((file) => {
45100
45161
  const absolutePath = path_1.default.join(pageDir, file);
@@ -45671,7 +45732,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45671
45732
  .map(route => {
45672
45733
  route = Object.assign({}, route);
45673
45734
  route.src = path_1.default.posix.join('^/', entryDirectory, '_next/data/', escapedBuildId, route.src.replace(/(^\^|\$$)/g, '') + '.json$');
45674
- const { pathname } = new URL(route.dest || '/', 'http://n');
45735
+ const { pathname, search } = new URL(route.dest || '/', 'http://n');
45675
45736
  let isPrerender = !!prerenders[path_1.default.join('./', pathname)];
45676
45737
  if (routesManifest.i18n) {
45677
45738
  for (const locale of routesManifest.i18n?.locales || []) {
@@ -45683,7 +45744,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45683
45744
  }
45684
45745
  }
45685
45746
  if (isPrerender) {
45686
- route.dest = `/_next/data/${buildId}${pathname}.json`;
45747
+ route.dest = `/_next/data/${buildId}${pathname}.json${search || ''}`;
45687
45748
  }
45688
45749
  return route;
45689
45750
  })
@@ -45784,31 +45845,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45784
45845
  status: 404,
45785
45846
  },
45786
45847
  ]),
45787
- // static 500 page if present
45788
- ...(!hasStatic500
45789
- ? []
45790
- : i18n
45791
- ? [
45792
- {
45793
- src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
45794
- .map(locale => (0, escape_string_regexp_1.default)(locale))
45795
- .join('|')})(/.*|$)`,
45796
- dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
45797
- status: 500,
45798
- },
45799
- {
45800
- src: path_1.default.join('/', entryDirectory, '.*'),
45801
- dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
45802
- status: 500,
45803
- },
45804
- ]
45805
- : [
45806
- {
45807
- src: path_1.default.join('/', entryDirectory, '.*'),
45808
- dest: path_1.default.join('/', entryDirectory, '/500'),
45809
- status: 500,
45810
- },
45811
- ]),
45848
+ // custom 500 page if present
45849
+ ...(i18n && (hasStatic500 || hasIsr500Page || lambdaPages['500.js'])
45850
+ ? [
45851
+ {
45852
+ src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
45853
+ .map(locale => (0, escape_string_regexp_1.default)(locale))
45854
+ .join('|')})(/.*|$)`,
45855
+ dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
45856
+ status: 500,
45857
+ caseSensitive: true,
45858
+ },
45859
+ {
45860
+ src: path_1.default.join('/', entryDirectory, '.*'),
45861
+ dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
45862
+ status: 500,
45863
+ },
45864
+ ]
45865
+ : [
45866
+ {
45867
+ src: path_1.default.join('/', entryDirectory, '.*'),
45868
+ dest: path_1.default.join('/', entryDirectory, hasStatic500 ||
45869
+ hasIsr500Page ||
45870
+ lambdas[path_1.default.join(entryDirectory, '500')]
45871
+ ? '/500'
45872
+ : '/_error'),
45873
+ status: 500,
45874
+ },
45875
+ ]),
45812
45876
  ],
45813
45877
  };
45814
45878
  }
@@ -47377,6 +47441,11 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
47377
47441
  const shortPath = edgeFile.replace(/^pages\//, '');
47378
47442
  worker.edgeFunction.name = shortPath;
47379
47443
  source.edgeFunctions[shortPath] = worker.edgeFunction;
47444
+ // we don't add the route for edge functions as these
47445
+ // are already added in the routes-manifest under dynamicRoutes
47446
+ if (worker.type === 'function') {
47447
+ continue;
47448
+ }
47380
47449
  const route = {
47381
47450
  continue: true,
47382
47451
  src: worker.routeSrc,
@@ -47388,14 +47457,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
47388
47457
  },
47389
47458
  ],
47390
47459
  };
47391
- if (worker.type === 'function') {
47392
- route.dest = shortPath;
47393
- }
47394
- else {
47395
- route.middlewarePath = shortPath;
47396
- if (isCorrectMiddlewareOrder) {
47397
- route.override = true;
47398
- }
47460
+ route.middlewarePath = shortPath;
47461
+ if (isCorrectMiddlewareOrder) {
47462
+ route.override = true;
47399
47463
  }
47400
47464
  if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
47401
47465
  source.dynamicRouteMap.set(worker.page, route);
@@ -21,13 +21,20 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
21
21
  const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
22
22
  const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
23
23
  const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
24
- async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, trailingSlash, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
24
+ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
25
+ lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
25
26
  const lambdas = {};
26
27
  const prerenders = {};
27
28
  const lambdaPageKeys = Object.keys(lambdaPages);
28
29
  const internalPages = ['_app.js', '_error.js', '_document.js'];
29
30
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
30
31
  const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
32
+ let appBuildTraces = {};
33
+ let appDir = null;
34
+ if (appPathRoutesManifest) {
35
+ appDir = path_1.default.join(pagesDir, '../app');
36
+ appBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', appDir);
37
+ }
31
38
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
32
39
  const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
33
40
  const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
@@ -264,9 +271,21 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
264
271
  const compressedPages = {};
265
272
  const mergedPageKeys = [...nonApiPages, ...apiPages, ...internalPages];
266
273
  const traceCache = {};
274
+ const getOriginalPagePath = (page) => {
275
+ let originalPagePath = page;
276
+ if (appDir && lambdaAppPaths[page]) {
277
+ const { fsPath } = lambdaAppPaths[page];
278
+ originalPagePath = path_1.default.relative(appDir, fsPath);
279
+ }
280
+ return originalPagePath;
281
+ };
282
+ const getBuildTraceFile = (page) => {
283
+ return (pageBuildTraces[page + '.nft.json'] ||
284
+ appBuildTraces[page + '.nft.json']);
285
+ };
267
286
  const pathsToTrace = mergedPageKeys
268
287
  .map(page => {
269
- if (!pageBuildTraces[page + '.nft.json']) {
288
+ if (!getBuildTraceFile(page)) {
270
289
  return lambdaPages[page].fsPath;
271
290
  }
272
291
  })
@@ -284,13 +303,31 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
284
303
  }
285
304
  for (const page of mergedPageKeys) {
286
305
  const tracedFiles = {};
287
- const pageBuildTrace = pageBuildTraces[page + '.nft.json'];
306
+ const originalPagePath = getOriginalPagePath(page);
307
+ const pageBuildTrace = getBuildTraceFile(originalPagePath);
288
308
  let fileList;
289
309
  let reasons;
290
310
  if (pageBuildTrace) {
291
311
  const { files } = JSON.parse(await fs_extra_1.default.readFile(pageBuildTrace.fsPath, 'utf8'));
312
+ // TODO: this will be moved to a separate worker in the future
313
+ // although currently this is needed in the lambda
314
+ const isAppPath = appDir && lambdaAppPaths[page];
315
+ const serverComponentFile = isAppPath
316
+ ? pageBuildTrace.fsPath.replace(/\.js\.nft\.json$/, '.__sc_client__.js')
317
+ : null;
318
+ if (serverComponentFile && (await fs_extra_1.default.pathExists(serverComponentFile))) {
319
+ files.push(path_1.default.relative(path_1.default.dirname(pageBuildTrace.fsPath), serverComponentFile));
320
+ try {
321
+ const scTrace = JSON.parse(await fs_extra_1.default.readFile(`${serverComponentFile}.nft.json`, 'utf8'));
322
+ scTrace.files.forEach((file) => files.push(file));
323
+ }
324
+ catch (err) {
325
+ /* non-fatal for now */
326
+ }
327
+ }
292
328
  fileList = [];
293
- const pageDir = path_1.default.dirname(path_1.default.join(pagesDir, page));
329
+ const curPagesDir = isAppPath && appDir ? appDir : pagesDir;
330
+ const pageDir = path_1.default.dirname(path_1.default.join(curPagesDir, originalPagePath));
294
331
  const normalizedBaseDir = `${baseDir}${baseDir.endsWith('/') ? '' : '/'}`;
295
332
  files.forEach((file) => {
296
333
  const absolutePath = path_1.default.join(pageDir, file);
@@ -867,7 +904,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
867
904
  .map(route => {
868
905
  route = Object.assign({}, route);
869
906
  route.src = path_1.default.posix.join('^/', entryDirectory, '_next/data/', escapedBuildId, route.src.replace(/(^\^|\$$)/g, '') + '.json$');
870
- const { pathname } = new URL(route.dest || '/', 'http://n');
907
+ const { pathname, search } = new URL(route.dest || '/', 'http://n');
871
908
  let isPrerender = !!prerenders[path_1.default.join('./', pathname)];
872
909
  if (routesManifest.i18n) {
873
910
  for (const locale of routesManifest.i18n?.locales || []) {
@@ -879,7 +916,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
879
916
  }
880
917
  }
881
918
  if (isPrerender) {
882
- route.dest = `/_next/data/${buildId}${pathname}.json`;
919
+ route.dest = `/_next/data/${buildId}${pathname}.json${search || ''}`;
883
920
  }
884
921
  return route;
885
922
  })
@@ -980,31 +1017,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
980
1017
  status: 404,
981
1018
  },
982
1019
  ]),
983
- // static 500 page if present
984
- ...(!hasStatic500
985
- ? []
986
- : i18n
987
- ? [
988
- {
989
- src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
990
- .map(locale => (0, escape_string_regexp_1.default)(locale))
991
- .join('|')})(/.*|$)`,
992
- dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
993
- status: 500,
994
- },
995
- {
996
- src: path_1.default.join('/', entryDirectory, '.*'),
997
- dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
998
- status: 500,
999
- },
1000
- ]
1001
- : [
1002
- {
1003
- src: path_1.default.join('/', entryDirectory, '.*'),
1004
- dest: path_1.default.join('/', entryDirectory, '/500'),
1005
- status: 500,
1006
- },
1007
- ]),
1020
+ // custom 500 page if present
1021
+ ...(i18n && (hasStatic500 || hasIsr500Page || lambdaPages['500.js'])
1022
+ ? [
1023
+ {
1024
+ src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
1025
+ .map(locale => (0, escape_string_regexp_1.default)(locale))
1026
+ .join('|')})(/.*|$)`,
1027
+ dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
1028
+ status: 500,
1029
+ caseSensitive: true,
1030
+ },
1031
+ {
1032
+ src: path_1.default.join('/', entryDirectory, '.*'),
1033
+ dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
1034
+ status: 500,
1035
+ },
1036
+ ]
1037
+ : [
1038
+ {
1039
+ src: path_1.default.join('/', entryDirectory, '.*'),
1040
+ dest: path_1.default.join('/', entryDirectory, hasStatic500 ||
1041
+ hasIsr500Page ||
1042
+ lambdas[path_1.default.join(entryDirectory, '500')]
1043
+ ? '/500'
1044
+ : '/_error'),
1045
+ status: 500,
1046
+ },
1047
+ ]),
1008
1048
  ],
1009
1049
  };
1010
1050
  }
package/dist/utils.js CHANGED
@@ -1457,6 +1457,11 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1457
1457
  const shortPath = edgeFile.replace(/^pages\//, '');
1458
1458
  worker.edgeFunction.name = shortPath;
1459
1459
  source.edgeFunctions[shortPath] = worker.edgeFunction;
1460
+ // we don't add the route for edge functions as these
1461
+ // are already added in the routes-manifest under dynamicRoutes
1462
+ if (worker.type === 'function') {
1463
+ continue;
1464
+ }
1460
1465
  const route = {
1461
1466
  continue: true,
1462
1467
  src: worker.routeSrc,
@@ -1468,14 +1473,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1468
1473
  },
1469
1474
  ],
1470
1475
  };
1471
- if (worker.type === 'function') {
1472
- route.dest = shortPath;
1473
- }
1474
- else {
1475
- route.middlewarePath = shortPath;
1476
- if (isCorrectMiddlewareOrder) {
1477
- route.override = true;
1478
- }
1476
+ route.middlewarePath = shortPath;
1477
+ if (isCorrectMiddlewareOrder) {
1478
+ route.override = true;
1479
1479
  }
1480
1480
  if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
1481
1481
  source.dynamicRouteMap.set(worker.page, route);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.1.18",
3
+ "version": "3.1.21",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -44,7 +44,7 @@
44
44
  "@types/semver": "6.0.0",
45
45
  "@types/text-table": "0.2.1",
46
46
  "@types/webpack-sources": "3.2.0",
47
- "@vercel/build-utils": "5.3.1",
47
+ "@vercel/build-utils": "5.3.2",
48
48
  "@vercel/nft": "0.21.0",
49
49
  "@vercel/routing-utils": "2.0.2",
50
50
  "async-sema": "3.0.1",
@@ -69,5 +69,5 @@
69
69
  "typescript": "4.5.2",
70
70
  "webpack-sources": "3.2.3"
71
71
  },
72
- "gitHead": "b52d01f809b80734ed1ab61df82f299f11a04720"
72
+ "gitHead": "6700630feb23bdb4e94ea727911a9e10aa546361"
73
73
  }