mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
fix(next/image): handle ?dpl for src without protocol (#86836)
Follow up to previous PR based on this comment: https://github.com/vercel/next.js/pull/86485#discussion_r2589758455 We want to avoid adding `?dpl` when the deployment is an absolute url missing the protocol which is allowed when `unoptimized=true`.
This commit is contained in:
@@ -232,7 +232,7 @@ function generateImgAttrs({
|
||||
}: GenImgAttrsData): GenImgAttrsResult {
|
||||
if (unoptimized) {
|
||||
const deploymentId = getDeploymentId()
|
||||
if (src.startsWith('/') && deploymentId) {
|
||||
if (src.startsWith('/') && !src.startsWith('//') && deploymentId) {
|
||||
const sep = src.includes('?') ? '&' : '?'
|
||||
src = `${src}${sep}dpl=${deploymentId}`
|
||||
}
|
||||
|
||||
@@ -796,4 +796,28 @@ describe('getImageProps()', () => {
|
||||
delete process.env.NEXT_DEPLOYMENT_ID
|
||||
}
|
||||
})
|
||||
it('should not add query string for unoptimized with no protocol when NEXT_DEPLOYMENT_ID defined', async () => {
|
||||
try {
|
||||
process.env.NEXT_DEPLOYMENT_ID = 'dpl_123'
|
||||
const { props } = getImageProps({
|
||||
alt: 'a nice desc',
|
||||
src: '//example.com/test.png',
|
||||
unoptimized: true,
|
||||
width: 100,
|
||||
height: 200,
|
||||
})
|
||||
expect(warningMessages).toStrictEqual([])
|
||||
expect(Object.entries(props)).toStrictEqual([
|
||||
['alt', 'a nice desc'],
|
||||
['loading', 'lazy'],
|
||||
['width', 100],
|
||||
['height', 200],
|
||||
['decoding', 'async'],
|
||||
['style', { color: 'transparent' }],
|
||||
['src', '//example.com/test.png'],
|
||||
])
|
||||
} finally {
|
||||
delete process.env.NEXT_DEPLOYMENT_ID
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user