Skip to content

feat: lift WordPress srcset 2048px ceiling for configured retina widths - #292

Merged
marcoluzi merged 2 commits into
mainfrom
feat/srcset-width-ceiling
Sep 11, 2026
Merged

feat: lift WordPress srcset 2048px ceiling for configured retina widths#292
marcoluzi merged 2 commits into
mainfrom
feat/srcset-width-ceiling

Conversation

@marcoluzi

Copy link
Copy Markdown
Member

Problem

WordPress' wp_calculate_image_srcset() drops any srcset candidate wider than max_srcset_image_width (default 2048px) unless the width matches the requested size exactly. Sproutset's @Nx variant feature generates files above 2048px, which were then silently excluded from the emitted srcset — wasted generation and broken retina intent above 2048.

Change

SrcsetWidthLimit reads the normalized image_sizes roster on boot and, when the largest configured width exceeds 2048, registers a max_srcset_image_width filter returning max(current, largest).

  • Scoped: registered only when a configured width actually exceeds 2048, so sites without large variants stay byte-identical to stock WP.
  • max(current, …) never lowers a value another plugin set higher.

Tests

Unit + integration (real WP) cover ceiling computation and live filter behavior, mapped 1:1 in specs/image-size-registration.md.

wp_calculate_image_srcset() excludes any candidate wider than the
max_srcset_image_width filter (default 2048px) unless the width matches
the requested size. Configured @nx variants above 2048px were therefore
generated on disk but silently dropped from the emitted srcset.

SrcsetWidthLimit reads the normalized image-size roster on boot and, when
the largest configured width exceeds 2048px, registers a
max_srcset_image_width filter returning max(current, largestWidth) so a
higher external value is never lowered. Output stays byte-identical when
no configured width exceeds the default.
@marcoluzi marcoluzi changed the title Lift WordPress srcset 2048px ceiling for configured retina widths feat: lift WordPress srcset 2048px ceiling for configured retina widths Sep 11, 2026
The recent wordpress-stubs bump types wp_get_registered_image_subsizes()
and wp_get_upload_dir() precisely, making the defensive is_numeric/
is_string guards and ?? fallbacks provably dead. Remove them and tighten
the normalizer's return shape to int<0, max> so add_image_size() accepts
the widths without an argument.type error. No runtime behavior change.
@marcoluzi
marcoluzi merged commit f85f6d8 into main Sep 11, 2026
5 checks passed
@marcoluzi
marcoluzi deleted the feat/srcset-width-ceiling branch September 11, 2026 10:44
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.

1 participant