Fix block preview for responsive style states#78538
Conversation
|
Size Change: +128 B (0%) Total Size: 7.98 MB 📦 View Changed
ℹ️ View Unchanged
|
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for fixing this!
I tested in the default styles panel width, and also at smaller and very narrow widths and the results are consistent.
Also checked a bunch of blocks. The desktop styles are now able to be previewed on top of the tablet styles.
There's a minor issue with content being pushed down for some blocks, but I'll leave it to you as to whether its worth fixing here or later.
Before
Kapture.2026-05-22.at.13.28.58.mp4
After
Kapture.2026-05-22.at.13.29.43.mp4
| .is-root-container { | ||
| width: ${ 100 / previewScale }%; | ||
| transform: scale(${ previewScale }); | ||
| transform-origin: center left; | ||
| } |
There was a problem hiding this comment.
I don't know if this is a huge deal, but I noticed on blocks like Table and Cover that the mobile viewport results in .is-root-container getting large widths, e.g., width: 95.75%;
For some reason this pushes the preview content down:
Aligning items on the body to flex-start, and setting the transform origin to top seems to keep it stable:
body{
padding: ${ previewPadding }px;
min-height:${ Math.round( minHeight ) }px;
display:flex;
align-items: flex-start;
}
.is-root-container {
width: ${ 100 / previewScale }%;
transform: scale(${ previewScale });
transform-origin: top left;
}
There was a problem hiding this comment.
Whoops had my screenshots mixed up. Fixed.
There was a problem hiding this comment.
Oh sheez, good point. I just retested on trunk and can reproduce that.
I was initially only clicking the viewport dropdown. On trunk it doesn't move around. I'll get a patch up to see.
Thanks!
There was a problem hiding this comment.
Fwiw I can see the issue with Cover and Table on default and tablet on this PR, and it's not happening on trunk.
There was a problem hiding this comment.
Yeah, I can reproduce that. I'll look into it. It might not be completely fixable without fixing the trunk issue also though. From what I can tell there are two different issues.
The trunk issue is the align-items: center that's set on the body. The PR issue is the transform-origin: center left; on the root container.
Maybe it makes sense to fix both in one go in this PR then.
There was a problem hiding this comment.
Maybe it makes sense to fix both in one go in this PR then.
Oh I didn't refresh the page and just saw this.
I'll close my PR.
Thank you!
There was a problem hiding this comment.
I've pushed some fixes (essentially what @ramonjd proposed) and it looks better to me now.
I do also think the block preview could be a little taller than 144px, especially on tablet/mobile browser windows. At 780px it looks like a thin strip.
It seems to be an inline style though.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |






What?
Fixes block previews for responsive states so that they show the correct styles
Why?
Previously when adding a style for tablet, and then switching to a mobile state the tablet style would still be displayed in the preview.
This was happening because the block preview's width was
500pxno matter what viewport was being selected.500pxis considered a tablet viewport size, so the preview was always picking up tablet styles.How?
The fix is to set the preview to an appropriate size for the selected responsive state. The preview is then scaled to counteract that so that the different size is not noticeable.
Currently these changes are only applied for
BlockPreviewPanelin global styles, I think that's the only place that needs the changes.Testing Instructions
Screenshots or screencast
Kapture.2026-05-22.at.11.02.50.mp4