Skip to content
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

Placeholder background-image SVG has an invalid property #408

Closed
robzor opened this issue Jun 17, 2024 · 2 comments
Closed

Placeholder background-image SVG has an invalid property #408

robzor opened this issue Jun 17, 2024 · 2 comments
Labels

Comments

@robzor
Copy link

robzor commented Jun 17, 2024

Describe the bug

When using the pictureTag() function, the placeholder SVG code appears to have an invalid property according to the Chrome dev tools.

An example of the outputted tag:

<img class="lazyload" src="<img url here>" width="1440" height="1223" alt=" " style="background-image: url(data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%271440%27 height=%271223%27 style=%27background:%23CCC%27 /%3E); background-size: cover;" loading="lazy">

To reproduce

Example code that triggers the issue:

{{ tiCardImage.imageTransformMax.pictureTag()
                        .pictureAttrs({
                            'class': 'ti-card__image',
                        })
                        .imgAttrs({
                            'alt': tiCardImage.alt ??? ' ',
                        })
                        .loadingStrategy('lazy')
                        .render() }}

Expected behaviour

No error in Chrome for the SVG tag.

Screenshots

CleanShot 2024-06-17 at 12  51 03

Versions

  • Plugin version: 5.0.1
  • Craft version: 5.2.0
  • Hosting: Servd
@robzor robzor added the bug label Jun 17, 2024
khalwat added a commit that referenced this issue Jun 18, 2024
…t in some browsers because the spaces were not URL-encoded ([#408](#408))
khalwat added a commit that referenced this issue Jun 18, 2024
…t in some browsers because the spaces were not URL-encoded ([#408](#408))
khalwat added a commit that referenced this issue Jun 18, 2024
…orrect in some browsers because the spaces were not URL-encoded ([#408](#408))
@khalwat
Copy link
Contributor

khalwat commented Jun 18, 2024

Addressed in the above commits.

Interestingly, I had a meticulously-written function just to do this: https://github.com/nystudio107/craft-imageoptimize/blob/develop-v5/src/services/OptimizedImages.php#L425 that was based on this article:

https://codepen.io/tigt/post/optimizing-svgs-in-data-uris

...but apparently, it was wrong, or browsers became more strict. Because replacing %20 with a is apparently what was breaking the style in Chrome.

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-imageoptimize": "dev-develop as 1.6.55”,

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-imageoptimize": "dev-develop-v4 as 4.0.9”,

Then do a composer clear-cache && composer update

…..

Craft CMS 5:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-imageoptimize": "dev-develop-v5 as 5.0.2”,

Then do a composer clear-cache && composer update

@khalwat khalwat closed this as completed Jun 18, 2024
@robzor
Copy link
Author

robzor commented Jun 18, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants