diff --git a/packages/next/next-server/lib/post-process.ts b/packages/next/next-server/lib/post-process.ts index d922a56bd174c18..fcbefe997a2d775 100644 --- a/packages/next/next-server/lib/post-process.ts +++ b/packages/next/next-server/lib/post-process.ts @@ -191,8 +191,10 @@ class ImageOptimizerMiddleware implements PostProcessMiddleware { } function isImgEligible(imgElement: HTMLElement): boolean { + let imgSrc = imgElement.getAttribute('src') return ( - imgElement.hasAttribute('src') && + !!imgSrc && + sourceIsSupportedType(imgSrc) && imageIsNotTooSmall(imgElement) && imageIsNotHidden(imgElement) ) @@ -243,6 +245,11 @@ function imageIsNotHidden(imgElement: HTMLElement): boolean { return true } +// Currently only filters out svg images--could be made more specific in the future. +function sourceIsSupportedType(imgSrc: string): boolean { + return !imgSrc.includes('.svg') +} + // Initialization registerPostProcessor( 'Inline-Fonts', diff --git a/test/integration/image-optimization/pages/index.js b/test/integration/image-optimization/pages/index.js index 09dec13363566a1..abbbb7dbbad2b48 100644 --- a/test/integration/image-optimization/pages/index.js +++ b/test/integration/image-optimization/pages/index.js @@ -6,6 +6,7 @@ const Page = () => { +