From 1304c79074d76b4f477a6f2df1e369e4fd7086e0 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 27 Jun 2024 23:17:08 +0200 Subject: [PATCH 1/6] Add deployment id header for rsc payload if present --- .../components/router-reducer/fetch-server-response.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/next/src/client/components/router-reducer/fetch-server-response.ts b/packages/next/src/client/components/router-reducer/fetch-server-response.ts index 4f29a43919f30..8490d7362c5d3 100644 --- a/packages/next/src/client/components/router-reducer/fetch-server-response.ts +++ b/packages/next/src/client/components/router-reducer/fetch-server-response.ts @@ -56,6 +56,7 @@ export async function fetchServerResponse( [NEXT_ROUTER_STATE_TREE]: string [NEXT_URL]?: string [NEXT_ROUTER_PREFETCH_HEADER]?: '1' + 'x-deployment-id'?: string } = { // Enable flight response [RSC_HEADER]: '1', @@ -79,6 +80,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', From 2899c7a77ceaf145e673cffa36bfd56fb96c6c2c Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 1 Jul 2024 17:52:20 +0200 Subject: [PATCH 2/6] add test --- .../app/app/from-app/page.tsx | 7 ++++- .../app/app/other-app/page.tsx | 24 +++++++++++++++++ .../deployment-id-handling/app/global.css | 2 +- .../deployment-id-handling.test.ts | 27 ++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 test/production/deployment-id-handling/app/app/other-app/page.tsx diff --git a/test/production/deployment-id-handling/app/app/from-app/page.tsx b/test/production/deployment-id-handling/app/app/from-app/page.tsx index 3fe13fd21f25b..048ad523fc0e5 100644 --- a/test/production/deployment-id-handling/app/app/from-app/page.tsx +++ b/test/production/deployment-id-handling/app/app/from-app/page.tsx @@ -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 ( @@ -19,6 +21,9 @@ export default function Page() { > click me + + other app + ) } diff --git a/test/production/deployment-id-handling/app/app/other-app/page.tsx b/test/production/deployment-id-handling/app/app/other-app/page.tsx new file mode 100644 index 0000000000000..0822e92df3c50 --- /dev/null +++ b/test/production/deployment-id-handling/app/app/other-app/page.tsx @@ -0,0 +1,24 @@ +'use client' +import testImage from '../../public/test.jpg' +import Image from 'next/image' + +export default function Page() { + return ( + <> +

other app

+ test +

{process.env.NEXT_DEPLOYMENT_ID}

+ + + + ) +} diff --git a/test/production/deployment-id-handling/app/global.css b/test/production/deployment-id-handling/app/global.css index af9c754fa2cc5..57ad414c1827c 100644 --- a/test/production/deployment-id-handling/app/global.css +++ b/test/production/deployment-id-handling/app/global.css @@ -1,5 +1,5 @@ html { - font-size: 14rem; + font-size: 1.4rem; color: white; background: black; } diff --git a/test/production/deployment-id-handling/deployment-id-handling.test.ts b/test/production/deployment-id-handling/deployment-id-handling.test.ts index 895b0ce992d29..eb968d668a3bd 100644 --- a/test/production/deployment-id-handling/deployment-id-handling.test.ts +++ b/test/production/deployment-id-handling/deployment-id-handling.test.ts @@ -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'])( @@ -81,8 +81,33 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])( }) } ) + + it('should contain deployment id in RSC payload request headers', async () => { + const browser = await next.browser('/from-app') + const rscHeaders = [] + browser.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(rscHeaders.length).toBeGreaterThan(0) + expect(await browser.elementByCss('h1').text()).toBe('other app') + expect(await browser.url()).toContain('/other-app') + }) + + expect( + rscHeaders.every( + (headers) => headers['x-deployment-id'] === deploymentId + ) + ).toBe(true) + }) } ) + describe('deployment-id-handling disabled', () => { const deploymentId = Date.now() + '' const { next } = nextTestSetup({ From 0f35bacd5b2046a6401f6b5f1f30c02cfb264ca7 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 1 Jul 2024 18:26:38 +0200 Subject: [PATCH 3/6] ignore in turbo build manifest --- test/turbopack-build-tests-manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/turbopack-build-tests-manifest.json b/test/turbopack-build-tests-manifest.json index 26cd246d94ca2..01c1032d89c42 100644 --- a/test/turbopack-build-tests-manifest.json +++ b/test/turbopack-build-tests-manifest.json @@ -15405,10 +15405,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": [], From ceae2cc5a516d3a8616d307463805bb30b1ac6ac Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 1 Jul 2024 19:03:59 +0200 Subject: [PATCH 4/6] solid tests --- .../deployment-id-handling/deployment-id-handling.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/production/deployment-id-handling/deployment-id-handling.test.ts b/test/production/deployment-id-handling/deployment-id-handling.test.ts index eb968d668a3bd..1c984ec7f0525 100644 --- a/test/production/deployment-id-handling/deployment-id-handling.test.ts +++ b/test/production/deployment-id-handling/deployment-id-handling.test.ts @@ -94,9 +94,9 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])( await browser.elementByCss('#other-app').click() await retry(async () => { - expect(rscHeaders.length).toBeGreaterThan(0) expect(await browser.elementByCss('h1').text()).toBe('other app') expect(await browser.url()).toContain('/other-app') + expect(rscHeaders.length).toBeGreaterThan(0) }) expect( From 75a0d07c9b562d5fb7b14f975d80b4701c58cc87 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 29 Jul 2024 18:44:17 -0700 Subject: [PATCH 5/6] update test --- .../deployment-id-handling/deployment-id-handling.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/production/deployment-id-handling/deployment-id-handling.test.ts b/test/production/deployment-id-handling/deployment-id-handling.test.ts index 1c984ec7f0525..e946ebe209ce3 100644 --- a/test/production/deployment-id-handling/deployment-id-handling.test.ts +++ b/test/production/deployment-id-handling/deployment-id-handling.test.ts @@ -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() From e66137251a35fabf16bd0366c4d01e68b3a9b3b1 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 29 Jul 2024 18:51:23 -0700 Subject: [PATCH 6/6] rework from flakiness --- .../deployment-id-handling.test.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/production/deployment-id-handling/deployment-id-handling.test.ts b/test/production/deployment-id-handling/deployment-id-handling.test.ts index e946ebe209ce3..15f39f76ad0f2 100644 --- a/test/production/deployment-id-handling/deployment-id-handling.test.ts +++ b/test/production/deployment-id-handling/deployment-id-handling.test.ts @@ -85,14 +85,18 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])( ) it('should contain deployment id in RSC payload request headers', async () => { - const browser = await next.browser('/from-app') const rscHeaders = [] - browser.on('request', async (req) => { - const headers = await req.allHeaders() - if (headers['rsc']) { - rscHeaders.push(headers) - } + 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 () => {