fix: expand bare vw sizes to all screen breakpoints#2180
fix: expand bare vw sizes to all screen breakpoints#2180daresTheDevil wants to merge 2 commits intonuxt:mainfrom
Conversation
When `sizes="100vw"` is used without a breakpoint prefix, parseSizes mapped it to a `1px` key. The fluid width calculation then produced `Math.round((100/100) * 1) = 1`, generating useless 1w/2w srcset entries instead of proper viewport-scaled widths. Bare fluid values (ending in `vw`) are now expanded to all configured screen breakpoints that aren't explicitly specified, so the vw→px calculation uses each screen's actual width. Fixed pixel values keep the original 1px sentinel behavior which was already correct. Examples of corrected output: - `sizes="100vw"` → srcset with 640w, 768w, 1024w, 1280w, 1536w - `sizes="50vw"` → srcset with 320w, 384w, 512w, 640w, 768w - `sizes="100vw lg:480px"` → 100vw for all screens except lg which gets 480px - `sizes="200,500:500,900:900"` → unchanged (fixed px, not affected) Closes nuxt#1433
commit: |
📝 WalkthroughWalkthroughA new exported constant Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2180 +/- ##
==========================================
- Coverage 32.52% 31.85% -0.68%
==========================================
Files 7 7
Lines 372 383 +11
Branches 131 136 +5
==========================================
+ Hits 121 122 +1
- Misses 194 200 +6
- Partials 57 61 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes #1433.
sizes="100vw"generated1w/2wsrcset entries instead of proper viewport-scaled widths.Root cause:
parseSizesmapped bare values (no breakpoint prefix) to a"1px"key. For fluidvwvalues,getSizesVariantthen calculatedMath.round((100/100) * 1) = 1pixel width. The fluid calculation depends onscreenMaxWidth, andparseInt("1px") = 1.The fix: Bare fluid values (
vw) are now expanded to all configured screen breakpoints, so the vw→px math uses each screen's actual pixel width. Bare fixed pixel values keep the existing1pxsentinel behavior (which was already correct since the pixel calculation doesn't depend onscreenMaxWidth).sizes="100vw"1w, 2w640w, 768w, 1024w, 1280w, 1536wsizes="50vw"1w, 2w320w, 384w, 512w, 640w, 768wsizes="100vw lg:480px"1w, 2w, 480w, 960w640w, 768w, 480w, 960w, 1280w, 1536wsizes="200,500:500,900:900"Credit to @dbismut for identifying the root cause in the
parseSizesfunction.Test plan
100vwgenerates proper viewport-scaled srcset widths100vw lg:480pxfills remaining screens with 100vw