Unverified Commit 4080f635 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure id handling applies for dynamic import in pages (#51049)

Noticed this case wasn't handled in pages so added additional test
coverage and patched the case.
parent 480df200
......@@ -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
......
'use client'
import testImage from '../../../public/test.jpg'
import Image from 'next/image'
......@@ -6,6 +7,17 @@ export default function Page() {
<>
<p>hello app edge</p>
<Image src={testImage} alt="test" />
<button
onClick={() => {
import('../../../data').then((mod) => {
console.log('loaded data', mod)
})
}}
id="dynamic-import"
>
click me
</button>
</>
)
}
......
'use client'
import testImage from '../../public/test.jpg'
import Image from 'next/image'
......@@ -6,6 +7,17 @@ export default function Page() {
<>
<p>hello app</p>
<Image src={testImage} alt="test" />
<button
onClick={() => {
import('../../data').then((mod) => {
console.log('loaded data', mod)
})
}}
id="dynamic-import"
>
click me
</button>
</>
)
}
export const data = {
now: Date.now(),
}
......@@ -6,6 +6,17 @@ export default function Page() {
<>
<p>hello pages</p>
<Image src={testImage} alt="test image" />
<button
onClick={() => {
import('../data').then((mod) => {
console.log('loaded data', mod)
})
}}
id="dynamic-import"
>
click me
</button>
</>
)
}
......@@ -6,6 +6,17 @@ export default function Page() {
<>
<p>hello pages edge</p>
<Image src={testImage} alt="test image" />
<button
onClick={() => {
import('../data').then((mod) => {
console.log('loaded data', mod)
})
}}
id="dynamic-import"
>
click me
</button>
</>
)
}
......
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)
}
}
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment