-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 -
wagtail-grapple/grapple/types/images.py
Lines 153 to 161 in d8bb922
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." | |
) |
There was a problem hiding this comment.
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:
wagtail-grapple/grapple/types/images.py
Lines 24 to 25 in d8bb922
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Fixes #369