Skip to content
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

Avoid paint on popover when hovering content #46201

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

corentin-gautier
Copy link
Contributor

@corentin-gautier corentin-gautier commented Nov 30, 2022

What?

Popovers use outline instead of border but it seems to trigger paint when hovering elements inside the popover

Why?

Using border avoids triggering paint which is better for performances

How?

Replace the use of outline by border

Testing Instructions

  1. Open the developer console and enable paint flashing
  2. Open a color palette popover
  3. Hover over a circular picker
  4. There should not be paint of the entire popover area

Screenshots

Before

Screen.Recording.2022-11-30.at.14.01.11.mov

After

Screen.Recording.2022-11-30.at.14.02.35.mov

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 30, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @corentin-gautier! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@corentin-gautier corentin-gautier force-pushed the fix/popover-outline-paint branch from 451df21 to c412bec Compare November 30, 2022 13:21
@skorasaurus skorasaurus added the [Type] Performance Related to performance efforts label Nov 30, 2022
@ciampo ciampo added the [Package] Components /packages/components label Nov 30, 2022
@corentin-gautier corentin-gautier force-pushed the fix/popover-outline-paint branch from c412bec to 4a0a64e Compare December 1, 2022 11:00
@ciampo
Copy link
Contributor

ciampo commented Dec 1, 2022

@jasmussen do you have any context to why we may want to use outline instead of border for Popover? This PR is proposing a rendering perf improvement, but it uses border instead of outline.

@jasmussen
Copy link
Contributor

Based on this comment here, https://github.com/WordPress/gutenberg/pull/40740/files#diff-7895f8092f907d624abdbe647e2201f1cebe9198cd3fae6ba759b70a4c0bfef4R16, it appears to be related to popover positioning computations. @youknowriad might have more context, but it sounds like the math that positions the inserter benefits from the outline not counting towards the block footprint.

An alternate solution, not sure if it affects perf, is to use an inner box-shadow for the border. That should theoretically accomplish the same.

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @jasmussen says, we can't use border because it affects the computed position for the Popover

This PR trunk
Screenshot 2022-12-02 at 10 32 40 Screenshot 2022-12-02 at 10 32 45

I tried using box-shadow on my machine as suggested:

Click to see the code changes I applied
diff --git a/packages/components/src/popover/style.scss b/packages/components/src/popover/style.scss
index f91f08b84f..c99034234d 100644
--- a/packages/components/src/popover/style.scss
+++ b/packages/components/src/popover/style.scss
@@ -1,5 +1,10 @@
 $arrow-triangle-base-size: 14px;
 
+$shadow-popover-border-default: 0 0 0 $border-width $gray-400;
+$shadow-popover-border-default-alternate: 0 0 0 $border-width $gray-900;
+$shadow-popover-border-top-only: 0 #{-$border-width} 0 0 $gray-400;
+$shadow-popover-border-top-only-alternate: 0 #{-$border-width} 0 $gray-900;
+
 .components-popover {
 	z-index: z-index(".components-popover");
 
@@ -15,16 +20,16 @@ $arrow-triangle-base-size: 14px;
 
 .components-popover__content {
 	background: $white;
-	border: $border-width solid $gray-400;
-	box-shadow: $shadow-popover;
+	// Using `box-shadow` instead of `border` to avoid impacting
+	// popover computations.
+	box-shadow: $shadow-popover-border-default, $shadow-popover;
 	border-radius: $radius-block-ui;
 	box-sizing: border-box;
 	width: min-content;
 
 	// Alternate treatment for popovers that put them at elevation zero with high contrast.
 	.is-alternate & {
-		border-color: $gray-900;
-		box-shadow: none;
+		box-shadow: $shadow-popover-border-default-alternate;
 	}
 
 	// A style that gives the popover no visible ui.
@@ -41,7 +46,11 @@ $arrow-triangle-base-size: 14px;
 		overflow-y: visible;
 		width: auto;
 		border: none;
-		border-top-color: $gray-900;
+		box-shadow: $shadow-popover-border-top-only, $shadow-popover;
+	}
+
+	.components-popover.is-expanded.is-alternate & {
+		box-shadow: $shadow-popover-border-top-only-alternate, $shadow-popover;
 	}
 }

From a quick look:

  • paint flashes are still reduced as per this PR's intention
  • Popover looks like on trunk (and the new border still doesn't affect the Popover's position)

@corentin-gautier , do you mind applying the suggested changes from the code snippet above and check if it achieves the rendering perf improvement that you had in mind?

@corentin-gautier corentin-gautier force-pushed the fix/popover-outline-paint branch from 4a0a64e to 606920b Compare December 2, 2022 13:01
@corentin-gautier
Copy link
Contributor Author

@ciampo @jasmussen box-shadow doesn't trigger paint 👍

@corentin-gautier corentin-gautier force-pushed the fix/popover-outline-paint branch from 606920b to 9170cfd Compare December 2, 2022 13:15
@ciampo
Copy link
Contributor

ciampo commented Dec 2, 2022

Before merging, do you mind adding a CHANGELOG entry for the changes in the @wordpress/components package, as suggested by Aaron in this other PR?

@ciampo
Copy link
Contributor

ciampo commented Dec 2, 2022

@mirka or @tyxla do you mind giving this PR a final round of review? I'm not going to be around in the upcoming weeks

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good! Thanks @corentin-gautier 🙌

Let's have a CHANGELOG entry and I'm happy to ship it afterwards.

@corentin-gautier
Copy link
Contributor Author

This looks pretty good! Thanks @corentin-gautier 🙌

Let's have a CHANGELOG entry and I'm happy to ship it afterwards.

Done !

@tyxla
Copy link
Member

tyxla commented Dec 5, 2022

This looks pretty good! Thanks @corentin-gautier 🙌
Let's have a CHANGELOG entry and I'm happy to ship it afterwards.

Done !

Thanks, @corentin-gautier, but could you please rebase the branch to the latest trunk as well? It seems to have some conflicts currently.

remove border on unstyled/expanded

use box-shadow instead of border

remove shadow on alternate

update changelog
@corentin-gautier corentin-gautier force-pushed the fix/popover-outline-paint branch from e47d588 to a365a85 Compare December 5, 2022 10:24
@corentin-gautier
Copy link
Contributor Author

@tyxla and done ;)

@tyxla
Copy link
Member

tyxla commented Dec 5, 2022

Thanks again @corentin-gautier 🙌 Let me ship this for you.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyxla tyxla merged commit c8516e6 into WordPress:trunk Dec 5, 2022
@github-actions github-actions bot added this to the Gutenberg 14.8 milestone Dec 5, 2022
@corentin-gautier corentin-gautier deleted the fix/popover-outline-paint branch December 5, 2022 10:59
mpkelly pushed a commit to mpkelly/gutenberg that referenced this pull request Dec 7, 2022
remove border on unstyled/expanded

use box-shadow instead of border

remove shadow on alternate

update changelog

Co-authored-by: Corentin Gautier <corentin.gautier@consertotech.pro>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Components /packages/components [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants