fix(upgrade): prevent nextjs image blur property from modified (#16405)

Fix #16404

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
This commit is contained in:
Paul Nodet 2025-02-11 17:37:59 +01:00 • committed by GitHub
parent f678a7025f
commit 17c7c7ec30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View file

@ -68,4 +68,9 @@ test('does not replace classes in invalid positions', async () => {
await shouldNotReplace(`<div v-show="shadow"></div>\n`)
await shouldNotReplace(`<div x-if="shadow"></div>\n`)
await shouldNotReplace(`<div style={{filter: 'drop-shadow(30px 10px 4px #4444dd)'}}/>\n`)
// Next.js Image placeholder cases
await shouldNotReplace(`<Image placeholder="blur" src="/image.jpg" />`, 'blur')
await shouldNotReplace(`<Image placeholder={'blur'} src="/image.jpg" />`, 'blur')
await shouldNotReplace(`<Image placeholder={blur} src="/image.jpg" />`, 'blur')
})

View file

@ -10,6 +10,7 @@ const CONDITIONAL_TEMPLATE_SYNTAX = [
/x-if=['"]$/,
/x-show=['"]$/,
]
const NEXT_PLACEHOLDER_PROP = /placeholder=\{?['"]$/
export function isSafeMigration(location: { contents: string; start: number; end: number }) {
let currentLineBeforeCandidate = ''
@ -63,5 +64,10 @@ export function isSafeMigration(location: { contents: string; start: number; end
}
}
// Heuristic: Disallow Next.js Image `placeholder` prop
if (NEXT_PLACEHOLDER_PROP.test(currentLineBeforeCandidate)) {
return false
}
return true
}