-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix layout shift on zoom out in post/page editor. #65915
Conversation
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. |
@@ -21,6 +21,13 @@ | |||
margin-left: calc(-1 * (#{$prev-container-width} - #{$container-width}) / 2); | |||
} | |||
|
|||
// Avoid collapsing margins causing a layout shift when invoking zooming. | |||
.block-editor-iframe__body, |
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.
Note, it isn't clear to me that these are the best places to add these pieces of code, I'm happy to move it if you have suggestions.
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 .block-editor-iframe__body
can stay in this file, but
.editor-visual-editor__post-title-wrapper
is part of the editor package
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.
Good feedback, thank you. I can move this (especially if you have a recommendation) some time tomorrow. If you happen to have the branch checked out and want to push the changes directly, feel free to!
Size Change: +84 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in 16a72d6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11216244513
|
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.
Thanks for working on this one! This appears to fix the issue at the top for me, but I noticed that on an empty post/page, the bottom area also appears to shift (the area that's expanded to fill the viewport where there isn't yet any content). The issue is only visible for me on empty posts — if we add a whole bunch of blocks, we don't see the issue.
Here's a quick screengrab:
2024-10-08.15.41.38.mp4
I'm not sure what the fix would be for that, I did a tiny bit of hacking around without much luck unfortunately. Not a blocker to landing, as this PR is still an improvement over trunk, but if possible it'd be great to handle this case, too, if we can 🤔
My best bet was applying The real fix is to replace the I also tried addressing @MaggieCabrera's feedback here, but for whatever reason I cannot move the rule to any other files. I tried adding it to |
For context that rule originated from #45261 |
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.
Kudos on a simple and clever way to fix this Joen. Yet I'm wary because it makes a visual difference even when not zoomed out. Here’s TT4 with the proposed styles being toggled on/off:
65915-visual-difference.mp4
To restate, existing theme styling can be affected by this. I do think there’s potential to find an alternative that won’t do so.
I’d like to share what I understand of the causes for this issue. I see two parts to it, the layout shift Joen mentions is one. The layout shift is due to the The other part is that zoom out adds a background color on the |
Those flex rules may implicitly cause the shift because they prevent margin collapsing, but removing them would mean that the white area above the title disappears when zooming, so replacing one visual shift with another. In this beta period, I think I'd rather look for a way to prevent this margin collapsing, than to revert the flex rules, the former seems less risky, yet we do need this zoom stutter fixed for 6.7. The other option is to apply flex to the iframe also when not zoomed out, as flex/grid is one of the things that prevents margin collapsing. I can try a quick spike here. |
Created #65967 as an alternative. It's not clear to me which fix is better/safer. |
I remember that I checked to see if ✅ height: auto;❌ height: 100%; |
That was just a way to "undo/redo" the styles in one click for the demo. I should have noted that to avoid confusion. |
Since #66041 has been merged, I'll remove the backport label for this PR. |
Should this be closed then? |
Yes, thanks! |
What?
When zooming in or out in the post or page editors, or the site editor with "Show template" off, there's a very noticable jump and layout shift:
This layout shift is caused by collapsing margins, both on the
body
element of the editing canvas itself, and on the margins applied to the post title wrapper.By adding a thin invisible border, we prevent margin collapsing, and thus, prevent the layout shift from happening:
Testing Instructions
Test zooming in and out in post, page editors, or site editor with "Show template" turned off.