-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Perf: Only mount SpacingVisualizers when actively visualizing #72800
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
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. |
|
Size Change: +25 B (0%) Total Size: 2.45 MB
ℹ️ View Unchanged
|
Previously, PaddingVisualizer and MarginVisualizer components were always mounted whenever a block supported spacing, causing MutationObservers to run continuously and trigger re-renders on every canvas hover. Now only mounts visualizers when actively hovering padding/margin controls (visualizedProperty is set), preventing unnecessary MutationObserver overhead. Also adds useEffect to force style computation on mount to ensure correct dimensions display when visualizer first appears.
bcf7673 to
fd1560a
Compare
|
Flaky tests detected in fd1560a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19104325350
|
getdave
left a comment
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 tested this with various blocks and the dimensions panel behaved as it did previously.
Reviewing the code this avoids unnecessary subscriptions and avoids even rendering the visualisers if the respective property is not being visualized.
Overall this is an improvement over trunk.
What?
Previously, PaddingVisualizer and MarginVisualizer components were always mounted whenever a block supported spacing, causing MutationObservers to run continuously and trigger re-renders on every canvas hover.
Now only mounts visualizers when actively hovering padding/margin controls (visualizedProperty is set), preventing unnecessary MutationObserver overhead.
Also adds useEffect to force style computation on mount to ensure correct dimensions display when visualizer first appears.
Why?
We shouldn't be retriggering all these renders when we're not even using the functionality.
How?
Check to see if we want to be visualizing that property, then mount it. When force mounted also update the styles again so we get the correct values.
Testing Instructions
Interact with the dimensions panel on various blocks. There should be no changes from trunk.
Testing Instructions for Keyboard
Screenshots or screencast
Profiling before:
See how many renders hovering is, and how often the spacing visualizers show up.
Screen.Recording.2025-10-29.at.12.45.37.PM.mov
Afterwards, there is just render when hovering. The post locked modal, for some reason... going to look at that one :)
Screen.Recording.2025-10-29.at.12.46.29.PM.mov