#109899The f:image.srcset VH wrongly requires the srcset attribute (instead of defaulting to "1x"), the official HTML spec has it as optional (defaulting to "1x")
Description
See https://html.spec.whatwg.org/#srcset-attribute – zero or one
> Zero or one of the following:
> # A width descriptor, consisting of: ASCII whitespace, a valid non-negative integer giving a number greater than zero representing the width descriptor value, and a U+0077 LATIN SMALL LETTER W character.
> # A pixel density descriptor, consisting of: ASCII whitespace, a valid floating-point number giving a number greater than zero representing the pixel density descriptor value, and a U+0078 LATIN SMALL LETTER X character.
And Mozilla says explicitly this, https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/source#srcset
> If the descriptors are not specified, the default value used is 1x
However, the f:image.srcset ViewHelper has this:
$this->registerArgument(‘srcset’, ‘string’, ‘Comma-separated list of width descriptors (e. g. 200w) or pixel density descriptors (e. g. 2x).’, true);
So, the required flag set to true for the srcset argument. This is HTML-spec-violating.
Correct would be $required = false and $defaultValue = '1x'.
Of course, we could adjust hundreds of places by explcitly passing “1x” – but this is super-tedious and basically renders this VH useless (in the sense of comfort-gain). Much better would be if the VH behaves just fully compliant to the HTML-spec oob.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] The f:image.srcset VH wrongly requires the srcset attribute (instead of defaulting to "1x"), the official HTML spec has it as optional (defaulting to "1x") Resolves: #109899 Releases: main
History 3
-
Simon Praetorius commented <span data-processor="relativetime" data-value="2026-05-28T12:29:27+00:00" > 05/28/26, 12:29 </span>
-
Garvin Hicking changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2026-05-28T14:55:55+00:00" > 05/28/26, 14:55 </span> -
S P commented <span data-processor="relativetime" data-value="2026-05-29T05:31:25+00:00" > 05/29/26, 05:31 </span>
Simon Praetorius wrote in #note-1:
> Could you give an example how exactly you want to use the ViewHelper in your templates?Was just expermintenting. But for example this:
<source media="(min-width: 1024px)" srcset="{f:uri.image(image: image, cropVariant: 'desktop')}">would best be replaced by
<source media="(min-width: 1024px)" srcset="{f:image.srcset(image: image, cropVariant: 'desktop')}">but this is not possible. I have to explicitly add
srcset="1x", like so:<source media="(min-width: 1024px)" srcset="{f:image.srcset(image: image, cropVariant: 'desktop', srcset: '1x')}">This is not only tedious (no simple find-replace), but also leads to different HTML output. Semantically equivalent, yes, but still different, because now all final HTML srcset have the additional
" 1x"behind the URL. Increasing the file size without giving any improvement.The VH should default to
1xinternally and only render explicitly stated descriptors in the output (so: also render1xonly if it was explicitly given). Only this behaviour would be HTML-spec-conform and make the VH a replacement/life-simplifier in all use cases.
Could you give an example how exactly you want to use the ViewHelper in your templates?