Fix srcsetWidth methods to properly handle retina variants#432
Open
lukastransom wants to merge 1 commit intonystudio107:develop-v5from
Open
Fix srcsetWidth methods to properly handle retina variants#432lukastransom wants to merge 1 commit intonystudio107:develop-v5from
lukastransom wants to merge 1 commit intonystudio107:develop-v5from
Conversation
Contributor
|
I'm so sorry, this fell off of my radar. I'm planning to merge it in and backport it this week. Are there any changes since your initial PR? |
Author
|
This is the same patch I've been using for my 2 latest projects w/o issue. No additional changes on my end! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
getSrcsetSubsetArray()method fails when retina variants (2x, 3x) are configured, causingsrcsetWidth(),srcsetWidthWebP(), and related methods to return wrong variants.Index-based mapping between
variantSourceWidths(duplicated for retina) and sortedoptimizedImageUrlskeys breaks when looking up variants.Implemented Fix
Replace fragile index mapping with direct width analysis:
What's Been Tested
srcsetWidth*(),srcsetMinWidth*(),srcsetMaxWidth*()w) vs density descriptors (x)Configuration: 5 base widths (360, 442, 466, 559, 573) × 2 retina variants = 10 total
Before Fix (Broken)
{{ optimizedImages.srcsetWidthWebP(559, true) }} → .../884px/...webp 1x, .../932px/...webp 1x {# Wrong variants! #}After Fix (Correct)
{{ optimizedImages.srcsetWidthWebP(559, true) }} → .../559px/...webp 1x, .../1118px/...webp 2x {# Correct! #} {{ optimizedImages.srcsetWidthWebP(559, false) }} → .../559px/...webp 559w {# Only 1x variant #} {{ optimizedImages.srcsetMaxWidth(466, true) }} → 360px@1x, 720px@2x, 442px@1x, 884px@2x, 466px@1x, 932px@2xRelated Issues