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

Add deployment id header for rsc payload if present #67255

Merged
merged 11 commits into from
Jul 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function fetchServerResponse(
[NEXT_ROUTER_STATE_TREE_HEADER]: string
[NEXT_URL]?: string
[NEXT_ROUTER_PREFETCH_HEADER]?: '1'
'x-deployment-id'?: string
[NEXT_HMR_REFRESH_HEADER]?: '1'
// A header that is only added in test mode to assert on fetch priority
'Next-Test-Fetch-Priority'?: RequestInit['priority']
Expand Down Expand Up @@ -110,6 +111,10 @@ export async function fetchServerResponse(
headers[NEXT_URL] = nextUrl
}

if (process.env.NEXT_DEPLOYMENT_ID) {
headers['x-deployment-id'] = process.env.NEXT_DEPLOYMENT_ID
}

const uniqueCacheQuery = hexHash(
[
headers[NEXT_ROUTER_PREFETCH_HEADER] || '0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use client'
import testImage from '../../public/test.jpg'

import Link from 'next/link'
import Image from 'next/image'
import testImage from '../../public/test.jpg'

export default function Page() {
return (
Expand All @@ -19,6 +21,9 @@ export default function Page() {
>
click me
</button>
<Link id="other-app" href="/other-app">
other app
</Link>
</>
)
}
24 changes: 24 additions & 0 deletions test/production/deployment-id-handling/app/app/other-app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client'
import testImage from '../../public/test.jpg'
import Image from 'next/image'

export default function Page() {
return (
<>
<h1>other app</h1>
<Image src={testImage} alt="test" />
<p id="deploymentId">{process.env.NEXT_DEPLOYMENT_ID}</p>

<button
onClick={() => {
import('../../data').then((mod) => {
console.log('loaded data', mod)
})
}}
id="dynamic-import"
>
click me
</button>
</>
)
}
2 changes: 1 addition & 1 deletion test/production/deployment-id-handling/app/global.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html {
font-size: 14rem;
font-size: 1.4rem;
color: white;
background: black;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
import { check, retry } from 'next-test-utils'
import { join } from 'node:path'

describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])(
Expand Down Expand Up @@ -51,7 +51,9 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])(
const requests = []

browser.on('request', (req) => {
requests.push(req.url())
if (req.url().includes('/_next/static')) {
requests.push(req.url())
}
})

await browser.elementByCss('#dynamic-import').click()
Expand Down Expand Up @@ -81,8 +83,37 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])(
})
}
)

it('should contain deployment id in RSC payload request headers', async () => {
const rscHeaders = []
const browser = await next.browser('/from-app', {
beforePageLoad(page) {
page.on('request', async (req) => {
const headers = await req.allHeaders()
if (headers['rsc']) {
rscHeaders.push(headers)
}
})
},
})

await browser.elementByCss('#other-app').click()

await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('other app')
expect(await browser.url()).toContain('/other-app')
expect(rscHeaders.length).toBeGreaterThan(0)
})

expect(
rscHeaders.every(
(headers) => headers['x-deployment-id'] === deploymentId
)
).toBe(true)
})
}
)

describe('deployment-id-handling disabled', () => {
const deploymentId = Date.now() + ''
const { next } = nextTestSetup({
Expand Down
4 changes: 3 additions & 1 deletion test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15712,10 +15712,12 @@
"deployment-id-handling enabled with CUSTOM_DEPLOYMENT_ID should append dpl query to all assets correctly for /from-app",
"deployment-id-handling enabled with CUSTOM_DEPLOYMENT_ID should append dpl query to all assets correctly for /from-app/edge",
"deployment-id-handling enabled with CUSTOM_DEPLOYMENT_ID should append dpl query to all assets correctly for /pages-edge",
"deployment-id-handling enabled with CUSTOM_DEPLOYMENT_ID should contain deployment id in RSC payload request headers",
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should append dpl query to all assets correctly for /",
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should append dpl query to all assets correctly for /from-app",
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should append dpl query to all assets correctly for /from-app/edge",
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should append dpl query to all assets correctly for /pages-edge"
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should append dpl query to all assets correctly for /pages-edge",
"deployment-id-handling enabled with NEXT_DEPLOYMENT_ID should contain deployment id in RSC payload request headers"
],
"pending": [],
"flakey": [],
Expand Down
Loading