Skip to content

Commit 79330b7

Browse files
authored
perf(ripple): avoid page layouts from ripple elements (#17253)
A while ago we removed the `transform` from the `.mat-ripple` element in order to avoid creating extra layers for elements that the user isn't interacting with. As a result the ripple elements can cause layouts to be triggered on the entire page, which is noticeable on larger pages (see #17252). These changes are a hybrid solution where we add the `transform`, but only if the `.mat-ripple` element has content. This isn't bulletproof since the `:empty` selector can be invalidated by whitespace. For now this is our best solution that works across browsers, until the `contain` property gets better support. Fixes #17252.
1 parent 4c08a88 commit 79330b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/material/core/ripple/_ripple.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ $mat-ripple-color-opacity: 0.1;
1313
// By default, every ripple container should have position: relative in favor of creating an
1414
// easy API for developers using the MatRipple directive.
1515
position: relative;
16+
17+
// Promote containers that have ripples to a new layer. We want to target `:not(:empty)`,
18+
// because we don't want all ripple containers to have their own layer since they're used in a
19+
// lot of places and the layer is only relevant while animating. Note that ideally we'd use
20+
// the `contain` property here (see #13175), because `:empty` can be broken by having extra
21+
// text inside the element, but it isn't very well supported yet.
22+
&:not(:empty) {
23+
transform: translateZ(0);
24+
}
1625
}
1726

1827
.mat-ripple.mat-ripple-unbounded {

0 commit comments

Comments
 (0)