fix: bypass IPX processing for SVG sources in NuxtImg#2181
fix: bypass IPX processing for SVG sources in NuxtImg#2181daresTheDevil wants to merge 1 commit intonuxt:mainfrom
Conversation
SVGs routed through IPX crash with HTTP 500 due to svgo/css-tree bundler issues. NuxtPicture already handles this by serving SVGs as-is — this brings NuxtImg in line with that behavior. Adds isSvg computed that short-circuits sizes, placeholder, and mainSrc for .svg sources. Explicit format conversion (e.g. format="png") still flows through to IPX. Fixes nuxt#2035 Fixes nuxt#1967 Fixes nuxt#2075 Closes nuxt#1891
commit: |
📝 WalkthroughWalkthroughThis pull request implements SVG passthrough logic in the NuxtImg component to bypass IPX raster-based image processing for SVG files. A new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/nuxt/image.test.ts (1)
633-645: Consider adding a test for placeholder behavior with SVGs.The implementation disables placeholders for SVGs (returns
falsefrom theplaceholdercomputed), but there's no explicit test verifying this behavior. Adding a test would strengthen coverage:it('disables placeholder for SVGs', () => { const wrapper = mountImage({ src: '/logo.svg', placeholder: true }) const img = wrapper.find('img') // Should render the SVG directly, not a blurred placeholder expect(img.element.getAttribute('src')).toBe('/logo.svg') })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/nuxt/image.test.ts` around lines 633 - 645, Add a unit test named "disables placeholder for SVGs" that uses the existing mountImage helper to mount an image with src '/logo.svg' and placeholder: true, then find the img element and assert that img.element.getAttribute('src') === '/logo.svg' and that no placeholder behavior is present (e.g., img.element.getAttribute('srcset') is falsy); this verifies the placeholder computed is disabled for SVGs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/nuxt/image.test.ts`:
- Around line 633-645: Add a unit test named "disables placeholder for SVGs"
that uses the existing mountImage helper to mount an image with src '/logo.svg'
and placeholder: true, then find the img element and assert that
img.element.getAttribute('src') === '/logo.svg' and that no placeholder behavior
is present (e.g., img.element.getAttribute('srcset') is falsy); this verifies
the placeholder computed is disabled for SVGs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2d2ccba1-3b8d-4c9e-8843-435fe9be90b5
📒 Files selected for processing (5)
src/runtime/components/NuxtImg.vuetest/e2e/__snapshots__/ipx.json5test/e2e/generate.test.tstest/nuxt/image.test.tstest/unit/bundle.test.ts
💤 Files with no reviewable changes (1)
- test/e2e/generate.test.ts
Summary
<NuxtImg>routes all images through IPX unconditionally, including SVGs. This causes HTTP 500 errors because IPX's svgo/css-tree dependency chain has a broken dynamicrequire()that Nitro's bundler can't resolve at build time.<NuxtPicture>already handles this correctly. It detects SVG sources and returns the rawsrcwithout IPX processing. This PR bringsNuxtImgin line with that behavior.SVGs are vector images. They don't benefit from raster resize, srcset density variants, or placeholder blur. Sending them through IPX is both unnecessary and broken.
What changed
isSvgcomputed that detects.svgextension (case-insensitive, handles query strings and hashes)sizes,placeholder, andmainSrcfor SVG sources<NuxtImg src="/logo.svg" format="png" />) still flows through to IPXFixes #2035
Fixes #1967
Fixes #2075
Closes #1891
Test plan
tacos.svgnow served directly instead of through/_ipx/