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

Implement preserveSvg flag for srcSet() #370

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

mgax
Copy link
Contributor

@mgax mgax commented Sep 26, 2023

Fixes #369

Copy link
Member

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all LGTM.

Left a provocation (well, a challenge question) and would love to hear your thought as an implementer

@@ -181,6 +197,7 @@ def resolve_src_set(
info: GraphQLResolveInfo,
sizes: list[int],
format: str | None = None,
preserve_svg: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a conversation in the Wagtail Slack, I am very much inclined to make preserve_svg default to True here (and on the rendition)

ie. until Wagtail (well, Willlow) can actually rasterize SVGs, the only way to work with SVGs is to use preserve_svg in Grapple, and preserve-svg in regular templates, which adds so much extra effort.

What d'ya think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it very much makes sense. I can't imagine a scenario where you would not want preserveSvg: true as a default, even if it were possible to rasterize them.

We need to make sure this doesn't break on Wagtail < 5 though; I remember the code was relying on the fact that, on old Wagtails, it would not be possible to change the default False value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be fine. as preserve_svg filters out non-SVG filters -

if instance.is_svg() and preserve_svg:
# when dealing with SVGs, we want to limit the filter specs to those that are safe
filter_specs = to_svg_safe_spec(filter_specs)
if not filter_specs:
raise TypeError(
"No valid filter specs for SVG. "
"See https://docs.wagtail.org/en/stable/topics/images.html#svg-images for details."
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but to_svg_safe_spec is imported only for Wagtail >= 5; just wanted to mention this, as there don't seem to be a CI matrix that includes older Wagtails:

if WAGTAIL_VERSION > (5, 0):
from wagtail.images.utils import to_svg_safe_spec


I can implement the change; do you feel it should be part of this PR or separate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we run tox with tox-gh-actions in CI, so the matrix is in https://github.com/torchbox/wagtail-grapple/blob/main/tox.ini

let's follow up in a separate PR. We'd want to wrap if instance.is_svg() and preserve_svg: in an if WAGTAIL_VERSION > (5, 0) to be sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we run tox with tox-gh-actions in CI, so the matrix is in https://github.com/torchbox/wagtail-grapple/blob/main/tox.ini

@zerolab I think something is missing. I couldn't find a CI job that mentioned an old version of Wagtail so I made a branch to see if I can break it. AFAICT this should have failed CI: mgax@7b52a38

@zerolab zerolab merged commit 9693007 into torchbox:main Sep 27, 2023
13 checks passed
@mgax mgax deleted the feature/srcset-preservesvg branch September 27, 2023 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add preserveSvg argument to ImageObjectType.srcSet
2 participants