Skip to content

Commit 4eacfbf

Browse files
committed
Load config.deploymentId
1 parent f1f93df commit 4eacfbf

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,5 +967,6 @@
967967
"966": "Expected process.nextTick to reject invalid arguments",
968968
"967": "The key \"%s\" under \"env\" in %sconfig is not allowed. https://nextjs.org/docs/messages/env-key-not-allowed",
969969
"968": "Invariant: getNextConfigEdge must only be called in edge runtime",
970-
"969": "Invariant: nextConfig couldn't be loaded"
970+
"969": "Invariant: nextConfig couldn't be loaded",
971+
"970": "process.env.NEXT_DEPLOYMENT_ID is missing but runtimeServerDeploymentId is enabled"
971972
}

packages/next/src/server/base-server.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,24 @@ export default abstract class Server<
447447
// TODO: should conf be normalized to prevent missing
448448
// values from causing issues as this can be user provided
449449
this.nextConfig = conf as NextConfigRuntime
450+
451+
if (this.nextConfig.experimental.runtimeServerDeploymentId) {
452+
if (!process.env.NEXT_DEPLOYMENT_ID) {
453+
throw new Error(
454+
'process.env.NEXT_DEPLOYMENT_ID is missing but runtimeServerDeploymentId is enabled'
455+
)
456+
}
457+
this.nextConfig = {
458+
...this.nextConfig,
459+
deploymentId: process.env.NEXT_DEPLOYMENT_ID,
460+
}
461+
} else {
462+
process.env.NEXT_DEPLOYMENT_ID = this.nextConfig.experimental
463+
.useSkewCookie
464+
? ''
465+
: this.nextConfig.deploymentId || ''
466+
}
467+
450468
this.hostname = hostname
451469
if (this.hostname) {
452470
// we format the hostname so that it can be fetched
@@ -502,13 +520,6 @@ export default abstract class Server<
502520

503521
this.nextFontManifest = this.getNextFontManifest()
504522

505-
if (this.nextConfig.experimental.runtimeServerDeploymentId !== true) {
506-
process.env.NEXT_DEPLOYMENT_ID = this.nextConfig.experimental
507-
.useSkewCookie
508-
? ''
509-
: this.nextConfig.deploymentId || ''
510-
}
511-
512523
this.renderOpts = {
513524
dir: this.dir,
514525
supportsDynamicResponse: true,

packages/next/src/server/route-modules/route-module.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,15 @@ export abstract class RouteModule<
190190
dynamicCssManifest: any
191191
interceptionRoutePatterns: RegExp[]
192192
} {
193+
let result
193194
if (process.env.NEXT_RUNTIME === 'edge') {
194195
const { getEdgePreviewProps } =
195196
require('../web/get-edge-preview-props') as typeof import('../web/get-edge-preview-props')
196197

197198
const maybeJSONParse = (str?: string) =>
198199
str ? JSON.parse(str) : undefined
199200

200-
return {
201+
result = {
201202
buildId: process.env.__NEXT_BUILD_ID || '',
202203
buildManifest: self.__BUILD_MANIFEST as any,
203204
fallbackBuildManifest: {} as any,
@@ -209,7 +210,7 @@ export abstract class RouteModule<
209210
notFoundRoutes: [],
210211
version: 4,
211212
preview: getEdgePreviewProps(),
212-
},
213+
} as const,
213214
routesManifest: {
214215
version: 4,
215216
caseSensitive: Boolean(process.env.__NEXT_CASE_SENSITIVE_ROUTES),
@@ -357,7 +358,7 @@ export abstract class RouteModule<
357358
}),
358359
]
359360

360-
return {
361+
result = {
361362
buildId,
362363
buildManifest,
363364
fallbackBuildManifest,
@@ -376,6 +377,20 @@ export abstract class RouteModule<
376377
.map((rewrite) => new RegExp(rewrite.regex)),
377378
}
378379
}
380+
381+
if (
382+
result.serverFilesManifest?.config.experimental?.runtimeServerDeploymentId
383+
) {
384+
if (!process.env.NEXT_DEPLOYMENT_ID) {
385+
throw new Error(
386+
'process.env.NEXT_DEPLOYMENT_ID is missing but runtimeServerDeploymentId is enabled'
387+
)
388+
}
389+
result.serverFilesManifest.config.deploymentId =
390+
process.env.NEXT_DEPLOYMENT_ID
391+
}
392+
393+
return result
379394
}
380395

381396
public async loadCustomCacheHandlers(
@@ -524,6 +539,15 @@ export abstract class RouteModule<
524539
throw new Error("Invariant: nextConfig couldn't be loaded")
525540
}
526541

542+
if (nextConfig.experimental?.runtimeServerDeploymentId) {
543+
if (!process.env.NEXT_DEPLOYMENT_ID) {
544+
throw new Error(
545+
'process.env.NEXT_DEPLOYMENT_ID is missing but runtimeServerDeploymentId is enabled'
546+
)
547+
}
548+
nextConfig.deploymentId = process.env.NEXT_DEPLOYMENT_ID
549+
}
550+
527551
return nextConfig
528552
}
529553

0 commit comments

Comments
 (0)