Skip to content

Commit f3da010

Browse files
committed
fixup
1 parent 2fb495c commit f3da010

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

packages/next/src/client/components/router-reducer/fetch-server-response.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
urlToUrlWithoutFlightMarker,
4242
} from '../../route-params'
4343
import type { NormalizedSearch } from '../segment-cache/cache-key'
44-
import { deploymentId } from '../../../shared/lib/deployment-id'
44+
import { getDeploymentId } from '../../../shared/lib/deployment-id'
4545

4646
const createFromReadableStream =
4747
createFromReadableStreamBrowser as (typeof import('react-server-dom-webpack/client.browser'))['createFromReadableStream']
@@ -330,6 +330,7 @@ export async function createFetch<T>(
330330
headers['Next-Test-Fetch-Priority'] = fetchPriority
331331
}
332332

333+
const deploymentId = getDeploymentId()
333334
if (deploymentId) {
334335
headers['x-deployment-id'] = deploymentId
335336
}

packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
omitUnusedArgs,
5757
} from '../../../../shared/lib/server-reference-info'
5858
import { revalidateEntireCache } from '../../segment-cache/cache'
59-
import { deploymentId } from '../../../../shared/lib/deployment-id'
59+
import { getDeploymentId } from '../../../../shared/lib/deployment-id'
6060

6161
const createFromFetch =
6262
createFromFetchBrowser as (typeof import('react-server-dom-webpack/client.browser'))['createFromFetch']
@@ -111,6 +111,7 @@ async function fetchServerAction(
111111
),
112112
}
113113

114+
const deploymentId = getDeploymentId()
114115
if (deploymentId) {
115116
headers['x-deployment-id'] = deploymentId
116117
}

packages/next/src/client/webpack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ declare const __webpack_require__: any
22
declare let __webpack_public_path__: string
33

44
import {
5-
deploymentId,
5+
getDeploymentId,
66
getDeploymentIdQueryOrEmptyString,
77
} from '../shared/lib/deployment-id'
88

99
// If we have a deployment ID, we need to append it to the webpack chunk names
1010
// I am keeping the process check explicit so this can be statically optimized
11-
if (deploymentId) {
11+
if (getDeploymentId()) {
1212
const suffix = getDeploymentIdQueryOrEmptyString()
1313
const getChunkScriptFilename = __webpack_require__.u
1414
__webpack_require__.u = (...args: any[]) =>

packages/next/src/server/route-modules/pages/pages-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type {
4242
GetStaticPaths,
4343
GetStaticProps,
4444
} from '../../../types'
45-
import { deploymentId } from '../../../shared/lib/deployment-id'
45+
import { getDeploymentId } from '../../../shared/lib/deployment-id'
4646

4747
export const getHandler = ({
4848
srcPage: originalSrcPage,
@@ -258,7 +258,7 @@ export const getHandler = ({
258258
buildId,
259259
customServer:
260260
Boolean(routerServerContext?.isCustomServer) || undefined,
261-
deploymentId: deploymentId,
261+
deploymentId: getDeploymentId(),
262262
},
263263
renderOpts: {
264264
params,

packages/next/src/shared/lib/deployment-id.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
export let deploymentId: string | undefined = process.env.NEXT_DEPLOYMENT_ID
1+
// This could also be a variable instead of a function, but some unit tests want to change the ID at
2+
// runtime. Even though that would never happen in a real deployment.
3+
export function getDeploymentId(): string | undefined {
4+
return process.env.NEXT_DEPLOYMENT_ID
5+
}
26

37
export function getDeploymentIdQueryOrEmptyString(): string {
8+
let deploymentId = getDeploymentId()
49
if (deploymentId) {
510
return `?dpl=${deploymentId}`
611
}

packages/next/src/shared/lib/image-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ImageLoaderPropsWithConfig } from './image-config'
22
import { findClosestQuality } from './find-closest-quality'
3-
import { deploymentId } from './deployment-id'
3+
import { getDeploymentId } from './deployment-id'
44

55
function defaultLoader({
66
config,
@@ -95,6 +95,7 @@ function defaultLoader({
9595

9696
const q = findClosestQuality(quality, config)
9797

98+
let deploymentId = getDeploymentId()
9899
return `${config.path}?url=${encodeURIComponent(src)}&w=${width}&q=${q}${
99100
src.startsWith('/_next/static/media/') && deploymentId
100101
? `&dpl=${deploymentId}`

packages/next/src/shared/lib/router/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { interpolateAs } from './utils/interpolate-as'
4343
import { disableSmoothScrollDuringRouteTransition } from './utils/disable-smooth-scroll'
4444
import type { Params } from '../../../server/request/params'
4545
import { MATCHED_PATH_HEADER } from '../../../lib/constants'
46-
import { deploymentId } from '../deployment-id'
46+
import { getDeploymentId } from '../deployment-id'
4747

4848
let resolveRewrites: typeof import('./utils/resolve-rewrites').default
4949
if (process.env.__NEXT_HAS_REWRITES) {
@@ -498,6 +498,7 @@ function fetchNextData({
498498
unstable_skipClientCache,
499499
}: FetchNextDataParams): Promise<FetchDataOutput> {
500500
const { href: cacheKey } = new URL(dataHref, window.location.href)
501+
const deploymentId = getDeploymentId()
501502
const getData = (params?: { method?: 'HEAD' | 'GET' }) =>
502503
fetchRetry(dataHref, isServerRender ? 3 : 1, {
503504
headers: Object.assign(

0 commit comments

Comments
 (0)