diff --git a/packages/next/src/client/index.tsx b/packages/next/src/client/index.tsx index bb6a92c1a249..cef2af77ee20 100644 --- a/packages/next/src/client/index.tsx +++ b/packages/next/src/client/index.tsx @@ -63,6 +63,21 @@ declare global { } } +// ensure dynamic imports have deployment id added if enabled +const getChunkScriptFilename = __webpack_require__.u + +// eslint-disable-next-line no-undef +__webpack_require__.u = (chunkId: any) => { + return ( + getChunkScriptFilename(chunkId) + + `${ + process.env.__NEXT_DEPLOYMENT_ID + ? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}` + : '' + }` + ) +} + type RenderRouteInfo = PrivateRouteInfo & { App: AppComponent scroll?: { x: number; y: number } | null diff --git a/test/production/deployment-id-handling/app/app/from-app/edge/page.tsx b/test/production/deployment-id-handling/app/app/from-app/edge/page.tsx index 819e6fc72ae4..1904b931b85b 100644 --- a/test/production/deployment-id-handling/app/app/from-app/edge/page.tsx +++ b/test/production/deployment-id-handling/app/app/from-app/edge/page.tsx @@ -1,3 +1,4 @@ +'use client' import testImage from '../../../public/test.jpg' import Image from 'next/image' @@ -6,6 +7,17 @@ export default function Page() { <>

hello app edge

test + + ) } 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 5a976df6cc72..38e852fc76d5 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,3 +1,4 @@ +'use client' import testImage from '../../public/test.jpg' import Image from 'next/image' @@ -6,6 +7,17 @@ export default function Page() { <>

hello app

test + + ) } diff --git a/test/production/deployment-id-handling/app/data.js b/test/production/deployment-id-handling/app/data.js new file mode 100644 index 000000000000..5c7a40e4584f --- /dev/null +++ b/test/production/deployment-id-handling/app/data.js @@ -0,0 +1,3 @@ +export const data = { + now: Date.now(), +} diff --git a/test/production/deployment-id-handling/app/pages/index.tsx b/test/production/deployment-id-handling/app/pages/index.tsx index 38981d83af44..671584dcee22 100644 --- a/test/production/deployment-id-handling/app/pages/index.tsx +++ b/test/production/deployment-id-handling/app/pages/index.tsx @@ -6,6 +6,17 @@ export default function Page() { <>

hello pages

test image + + ) } diff --git a/test/production/deployment-id-handling/app/pages/pages-edge.tsx b/test/production/deployment-id-handling/app/pages/pages-edge.tsx index abfb1d7f2217..74b9280717a1 100644 --- a/test/production/deployment-id-handling/app/pages/pages-edge.tsx +++ b/test/production/deployment-id-handling/app/pages/pages-edge.tsx @@ -6,6 +6,17 @@ export default function Page() { <>

hello pages edge

test image + + ) } 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 c69446d38379..c91beec171ea 100644 --- a/test/production/deployment-id-handling/deployment-id-handling.test.ts +++ b/test/production/deployment-id-handling/deployment-id-handling.test.ts @@ -1,4 +1,5 @@ import { createNextDescribe } from 'e2e-utils' +import { check } from 'next-test-utils' import { join } from 'node:path' const deploymentId = Date.now() + '' @@ -44,6 +45,28 @@ createNextDescribe( expect(link.attribs.href).toContain('dpl=' + deploymentId) } } + + const browser = await next.browser(urlPath) + const requests = [] + + browser.on('request', (req) => { + requests.push(req.url()) + }) + + await browser.elementByCss('#dynamic-import').click() + + await check( + () => (requests.length > 0 ? 'success' : JSON.stringify(requests)), + 'success' + ) + + try { + expect( + requests.every((item) => item.includes('dpl=' + deploymentId)) + ).toBe(true) + } finally { + require('console').error('requests', requests) + } } ) }