gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Allow device preview preset widths to differ from responsive breakpoints

Open sergiu-radu opened this issue 1 month ago • 16 comments

What problem does this address?

The editor’s device preview presets use the responsive breakpoints defined in theme.json to determine the canvas width. This couples two different purposes: the upper boundary of a responsive range and a representative width for previewing content within that range.

For example, Blocksy theme uses these existing breakpoints:

  • Mobile: 690px
  • Tablet: 1000px

After exposing these values through settings.viewport, we received multiple user reports that the Mobile preview looks more like a tablet and does not represent the narrower phone screens they are designing for.

Users can manually resize the canvas, but selecting Mobile again restores the wider preset. This adds repeated adjustments to their editing workflow.

Reducing settings.viewport.mobile would also change the responsive CSS and block visibility boundaries, so it cannot serve as a preview-only adjustment.

What is your proposed solution?

Allow themes or plugins to configure the default device preview widths independently of the responsive breakpoints, through a dedicated editor setting or a public filter.

For example:

Device Responsive breakpoint Default preview width
Mobile 690px 390px
Tablet 1000px 850px

Selecting Mobile would open a 390px canvas, while mobile styles would continue to apply throughout the configured mobile range.

WordPress would continue to manage the actual canvas width, native resizing, device detection, and responsive editing state. Preview widths should remain within their corresponding responsive ranges.

The current behavior should remain the default when no custom preview widths are provided.

sergiu-radu avatar Oct 12 '26 07:10 sergiu-radu

So a TLDR is that sometimes the biggest size specified by the breakpoint isn't really the appropriate size for the preview, so the preview size should be customizable.

I think it makes sense. After #84146 we'll also be showing the sizes, and it is noticable that often they don't make sense as a device size.

Being able to customize the height (or aspect ratio) would be another nice to have, as I think the current hardcoded aspect ratios are a bit behind the times.

talldan avatar Oct 13 '26 06:10 talldan

Hello @talldan,

That’s exactly the distinction we’re trying to address. Showing the dimensions in #84146 should make this more apparent, configurable height or aspect ratio would also be useful.

Would you consider introducing a public filter for the default canvas width used when selecting Mobile or Tablet?

A filter would cover our use case, selecting Mobile could open a 390px preview while retaining the existing 690px responsive breakpoint. Ideally, the filtered width would go through WordPress’s native canvas state so resizing, device detection, and responsive editing remain synchronized.

sergiu-radu avatar Oct 13 '26 07:10 sergiu-radu

I don't think that a filter is the right choice, as the values set by the filter might not be appropriate for every theme.json's viewports.

talldan avatar Oct 13 '26 07:10 talldan

I submitted that last comment too quickly.

I think we'd probably want to explore expanding settings.viewport to support this. It's probably not a high priority issue at the moment, but there is potentially a family of changes in the future that this could be part of. One is allowing custom viewports beyond just mobile / tablet. Another discussed change is supporting overlapping breakpoints, so that styles applied to tablet also apply to mobile.

talldan avatar Oct 13 '26 07:10 talldan

That makes sense. A theme.json setting would work well for our use case.

For example, one possible format could preserve the existing breakpoint definitions and add optional preview dimensions separately:

{
	"settings": {
		"viewport": {
			"mobile": "690px",
			"tablet": "1000px"
		},
		"viewportPreview": {
			"mobile": "350px",
			"tablet": "800px"
		}
	}
}

Here, responsive styles would continue to use the existing breakpoint boundaries, while selecting Mobile or Tablet would initialize the editor canvas at the corresponding preview width.

Preview widths could be validated against their viewport ranges. When omitted, WordPress could preserve its current behavior.

The naming and exact structure are just illustrative and could be adapted to accommodate height or aspect ratio as well. Our main requirement is being able to configure representative preview dimensions independently of responsive CSS boundaries.

sergiu-radu avatar Oct 13 '26 12:10 sergiu-radu

Thanks for including this in #85243!

Just to add some context: we’ve received several reports from Blocksy users who find the wider Mobile preview harder to work with. Having to resize it again whenever they select Mobile adds friction to their editing workflow.

Independent preview widths would be a valuable improvement for us, allowing a more representative phone preview while preserving the existing responsive breakpoints.

Would any additional examples or user feedback help with evaluating this?

sergiu-radu avatar Oct 21 '26 11:10 sergiu-radu

I'd like to work on this. Building on @talldan suggestion to expand settings.viewport, would one of these shapes work?

Option A: a separate key, as sergiu-radu suggested: "viewportPreview": { "mobile": "390px", "tablet": "850px" }

Option B: each viewport becomes an object, with the current string form still supported: "viewport": { "mobile": { "breakpoint": "690px", "preview": "390px" } }

In both cases, the preview width would default to the breakpoint when omitted, so the current behaviour is unchanged. Option B keeps each device's values together and leaves room for future additions like height or aspect ratio. Happy to go with whichever fits the planned custom viewport work best.

dhananjaykuber avatar Nov 04 '26 05:11 dhananjaykuber

Thanks @dhananjaykuber for offering to work on this!

Both options would cover our Blocksy use case. Option B looks like a good fit with the direction @talldan suggested, especially if the existing string format and default behavior remain supported.

Our main requirement is being able to choose a representative preview width without changing the responsive CSS boundaries. We’re flexible about the configuration format.

@talldan, would Option B be a suitable direction for an initial PR, or would you prefer keeping the preview settings separate? Your guidance would help move the implementation forward.

sergiu-radu avatar Nov 04 '26 08:11 sergiu-radu

Hi @talldan, just following up 🙂

With @dhananjaykuber offering to work on this, do you think it could be a candidate for WordPress 7.2, if timing allows? It would make a meaningful difference for our users, who currently need to resize the mobile preview repeatedly.

Some guidance on the preferred configuration would help get an initial PR moving. We understand there are other priorities, but would really appreciate your thoughts on whether this is a realistic target.

Thanks!

sergiu-radu avatar Nov 09 '26 08:11 sergiu-radu

Both options work for me. We just need to provide back compat for option B (continue to support each viewport being a string size as well as being an object), but it is perhaps tidier and it opens the possibility to add more options for each viewport in the future. @tellthemachines might also have some thoughts!

With @dhananjaykuber offering to work on this, do you think it could be a candidate for WordPress 7.2, if timing allows?

WordPress 7.2 is already deep in beta (https://make.wordpress.org/core/7-2/), no new enhancements are accepted, so it's not possible to consider this for inclusion, it'd have to be for 7.3.

talldan avatar Nov 11 '26 08:11 talldan

Thanks for clarifying, @talldan. Understood regarding the 7.2 feature freeze.

Once implemented, reviewed, and tested, could this potentially be considered for a later 7.2 maintenance release, or would the new configuration necessarily need to wait for 7.3?

This would be a valuable improvement for our users’ mobile editing workflow, so we’d appreciate understanding whether an earlier release might be possible.

sergiu-radu avatar Nov 11 '26 19:11 sergiu-radu

The minor releases for 7.2 will be bug fixes and security only, so it'll have to be for 7.3.

talldan avatar Nov 12 '26 02:11 talldan

We just need to provide back compat for option B (continue to support each viewport being a string size as well as being an object), but it is perhaps tidier and it opens the possibility to add more options for each viewport in the future.

Yes this seems the better option. We should still actively support declaring viewports as strings as well as objects, just like we do for padding, block spacing etc..

It's interesting because this seems to be a first with regards to themes defining how the editor UI will display 😄

tellthemachines avatar Nov 12 '26 03:11 tellthemachines

It's interesting because this seems to be a first with regards to themes defining how the editor UI will display 😄

Yeah, that crossed my mind too. The other option is that it's an API that the theme calls in functions.php (e.g. register_device_previews).

That's somewhat compelling because if we allowed custom viewports in the future the theme could provide translated labels (and possibly icons) via such a function:

register_viewports( array(
  array( 'key' => 'small', 'label' => __( 'Small' ), 'previewSize' => '400px' ),
  array( 'key' => 'medium', 'label' => __( 'Medium' ), 'previewSize' => '800px' ),
  array( 'key' => 'large', 'label' => __( 'Large' ), 'previewSize' => '1200px' ),
) );

talldan avatar Nov 12 '26 04:11 talldan

Thanks @talldan and @tellthemachines! I'll go with Option B: each settings.viewport entry can stay a string or be an object like { "breakpoint": "690px", "preview": "390px" }. If preview is missing, it falls back to the breakpoint, so current behaviour doesn't change. I'll leave a register_viewports() style API for later, when custom viewports come up, unless you'd prefer to start there. I'll open a PR soon.

dhananjaykuber avatar Nov 12 '26 05:11 dhananjaykuber

I've opened #86712 with Option B: each settings.viewport entry can be a string, as before, or { "breakpoint": "690px", "preview": "390px" }. Feedback welcome!

dhananjaykuber avatar Nov 12 '26 06:11 dhananjaykuber