-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Improve grid visualizer resize observation #68842
Improve grid visualizer resize observation #68842
Conversation
Size Change: -52 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
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.
Some review notes:
const observers = []; | ||
for ( const element of [ gridElement, ...gridElement.children ] ) { | ||
const observer = new window.ResizeObserver( () => { | ||
setGridInfo( getGridInfo( gridElement ) ); | ||
} ); | ||
observer.observe( element ); | ||
observers.push( observer ); | ||
} |
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.
It’s unnecessary to create a new ResizeObserver
instance for each element given the callback can be shared and here it can be.
paddingTop: `calc(${ paddingTop } + ${ borderTopWidth })`, | ||
paddingRight: `calc(${ paddingRight } + ${ borderRightWidth })`, | ||
paddingBottom: `calc(${ paddingBottom } + ${ borderBottomWidth })`, | ||
paddingLeft: `calc(${ paddingLeft } + ${ borderLeftWidth })`, | ||
inset: ` | ||
calc(${ paddingTop } + ${ borderTopWidth }) | ||
calc(${ paddingRight } + ${ borderRightWidth }) | ||
calc(${ paddingBottom } + ${ borderBottomWidth }) | ||
calc(${ paddingLeft } + ${ borderLeftWidth }) | ||
`, |
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.
This is extraneous but I felt that the current use of padding does not express the intent quite as well as positioning (inset
).
for ( const element of gridElement.children ) { | ||
contentBoxSpy.observe( element ); | ||
} |
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.
This didn’t seem necessary but I could be missing something. Careful scrutiny of this is warranted, methinks.
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. |
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.
LGTM! I wasn't able to figure out how to solve this problem, but this PR appears to work perfectly as expected.
What?
A follow up to #68230 where it was noted that:
A resize observer can detect that change, but it has to be specified to observe the border-box. That’s because vertical padding in most cases will affect not the content-box but the border-box.
Why?
Primarily, to have the keep the grid visualizer in sync with changes to global styles like margin/border/padding. I’ve also tried some additional changes that aim to reduce resource usage by instantiating less objects and observing fewer elements.
How?
The core changes are these:
There are a few more things that didn’t have to be changed and I will add review comments for explanation/discussion.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Before
grid-visulizer-v-global-styles-padding-block-before.mp4
After
grid-visulizer-v-global-styles-padding-block-after.mp4