Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update id env prefix #51588

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export function getDefineEnv({
'process.env.__NEXT_ACTIONS_DEPLOYMENT_ID': JSON.stringify(
config.experimental.useDeploymentIdServerActions
),
'process.env.__NEXT_DEPLOYMENT_ID': JSON.stringify(
'process.env.NEXT_DEPLOYMENT_ID': JSON.stringify(
config.experimental.deploymentId
),
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX':
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const addChunkSuffix =
return (
getOriginalChunk(chunkId) +
`${
process.env.__NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}`
process.env.NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.NEXT_DEPLOYMENT_ID}`
: ''
}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ async function fetchServerAction(
'Next-Action': actionId,
[NEXT_ROUTER_STATE_TREE]: JSON.stringify(state.tree),
...(process.env.__NEXT_ACTIONS_DEPLOYMENT_ID &&
process.env.__NEXT_DEPLOYMENT_ID
process.env.NEXT_DEPLOYMENT_ID
? {
'x-deployment-id': process.env.__NEXT_DEPLOYMENT_ID,
'x-deployment-id': process.env.NEXT_DEPLOYMENT_ID,
}
: {}),
...(state.nextUrl
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const addChunkSuffix =
return (
getOriginalChunk(chunkId) +
`${
process.env.__NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}`
process.env.NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.NEXT_DEPLOYMENT_ID}`
: ''
}`
)
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/client/route-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function hasPrefetch(link?: HTMLLinkElement): boolean {
const canPrefetch: boolean = hasPrefetch()

const getAssetQueryString = () => {
return process.env.__NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}`
return process.env.NEXT_DEPLOYMENT_ID
? `?dpl=${process.env.NEXT_DEPLOYMENT_ID}`
: ''
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default async function exportPage({

try {
if (renderOpts.deploymentId) {
process.env.__NEXT_DEPLOYMENT_ID = renderOpts.deploymentId
process.env.NEXT_DEPLOYMENT_ID = renderOpts.deploymentId
}
const { query: originalQuery = {} } = pathMap
const { page } = pathMap
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {

if (process.env.NEXT_RUNTIME !== 'edge') {
if (this.nextConfig.experimental.deploymentId) {
process.env.__NEXT_DEPLOYMENT_ID =
process.env.NEXT_DEPLOYMENT_ID =
this.nextConfig.experimental.deploymentId
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export default class NextNodeServer extends BaseServer {
this.compression = require('next/dist/compiled/compression')()
}

if (this.nextConfig.experimental.deploymentId) {
process.env.NEXT_DEPLOYMENT_ID = this.nextConfig.experimental.deploymentId
}

if (!this.minimalMode) {
this.imageResponseCache = new ResponseCache(this.minimalMode)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/shared/lib/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function defaultLoader({
return `${config.path}?url=${encodeURIComponent(src)}&w=${width}&q=${
quality || 75
}${
process.env.__NEXT_DEPLOYMENT_ID
? `&dpl=${process.env.__NEXT_DEPLOYMENT_ID}`
process.env.NEXT_DEPLOYMENT_ID
? `&dpl=${process.env.NEXT_DEPLOYMENT_ID}`
: ''
}`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

export function GET(req) {
return NextResponse.json({
deploymentId: process.env.NEXT_DEPLOYMENT_ID,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function Page() {
<>
<p>hello app edge</p>
<Image src={testImage} alt="test" />
<p id="deploymentId">{process.env.NEXT_DEPLOYMENT_ID}</p>

<button
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function Page() {
<>
<p>hello app</p>
<Image src={testImage} alt="test" />
<p id="deploymentId">{process.env.NEXT_DEPLOYMENT_ID}</p>

<button
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function handler(_req, res) {
res.json({ deploymentId: process.env.NEXT_DEPLOYMENT_ID })
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function Page() {
return (
<>
<p className={styles.template}>hello pages</p>
<p id="deploymentId">{process.env.NEXT_DEPLOYMENT_ID}</p>
<Image src={testImage} alt="test image" />

<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function Page() {
<>
<p>hello pages edge</p>
<Image src={testImage} alt="test image" />
<p id="deploymentId">{process.env.NEXT_DEPLOYMENT_ID}</p>

<button
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ createNextDescribe(
async ({ urlPath }) => {
const $ = await next.render$(urlPath)

expect($('#deploymentId').text()).toBe(deploymentId)

const scripts = Array.from($('script'))
expect(scripts.length).toBeGreaterThan(0)

Expand Down Expand Up @@ -64,5 +66,16 @@ createNextDescribe(
}
}
)

it.each([{ pathname: '/api/hello' }, { pathname: '/api/hello-app' }])(
'should have deployment id env available',
async ({ pathname }) => {
const res = await next.fetch(pathname)

expect(await res.json()).toEqual({
deploymentId,
})
}
)
}
)