-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x]: Unable to eager load multiple transforms with srcsets #11209
Comments
Wiejeben
added a commit
to Wiejeben/cms
that referenced
this issue
May 11, 2022
This pull request would fix srcset eager loading by maintaining the `format` provided by the the base transform. Also this pull request would add support for allowing srcset transforms on multiple transforms, see craftcms#11209.
This is already possible. You just need to add {% set query = craft.entries()
.section('blogArticles')
.orderBy('postDate')
.limit(8)
.with([
['coverImage', {
withTransforms: ['cardIndexLarge', '2x', 'cardIndexMedium', '2x', 'cardIndexSmall', '2x']
}],
]) %} |
Sorry, there was a bug that prevented this from working as intended. Fixed now for the next v3 and v4 releases. |
3.7.43 and 4.0.3 are out now with that fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
Description
Update: I made a pull request #11210.
Essentially what I'm trying to do is to eager load 3 different transforms with a
2x
srcset:cardIndexLarge
with2x
cardIndexMedium
with2x
cardIndexSmall
with2x
In order to eager load the base transforms I wrote the following:
As far as I'm aware, the current transform eager loading implementation only supports a single transform when combined with eager loading srcsets. This is to us the last step to achieving full eager loading!
When I add
2x
as the last item in the transforms array it will only eager loadcardIndexSmall
with 2x. However if I add the srcset aftercardIndexLarge
it will actually overwritecardIndexMedium
andcardIndexSmall
to thecardIndexLarge 2x
variant.The overwrites happen because the
$sizeValue, $sizeUnit
at 461 are being remembered from the previous loop:https://github.com/craftcms/cms/blob/a7b735321468a6cf7d73a0eb582aa610eb5fc390/src/services/AssetTransforms.php#L
In order to fix this I added
unset($sizeValue, $sizeUnit);
to the end of the foreach loop, this would allow me to apply srcset eager loading to multiple transforms like this:Apart from the
![Screenshot 2022-05-11 at 20 58 17](https://user-images.githubusercontent.com/2922378/167925706-9a5d6f19-95ae-447c-a7e2-1ad38bccbbf4.png)
format
it would eager load all srcsets correctly (that might be a different issue?):Unless the format is applied from the base transform during eager loading the srcset transforms will still be requested in every loop:
![Screenshot 2022-05-11 at 20 58 55](https://user-images.githubusercontent.com/2922378/167925817-7dc28558-016e-475b-a1f8-4778db3b51dd.png)
I have validated this fix will continue to work even when adding multiple srcsets like this:
Craft CMS version
3.4.41
PHP version
8.0.17
Operating system and version
Linux 5.10.104-linuxkit
Database type and version
MySQL 8.0.28
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.0-16)
Installed plugins and versions
No response
The text was updated successfully, but these errors were encountered: