Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
before #24045 (probably, I haven't tested it)
Description
Strictly speaking, this is a Chromium bug, but (AFAICT) the only workaround is to change the CSS in the expansion panel component.
Currently, in Chromium-based browsers, the presence of a CSS rule selector like .blah[style*="something"] *
means that any change to the style
attribute of any element, anywhere on the page will force a style recalculation of that element's entire subtree. There is currently a rule like this in expanion-panel
:
Additionally, since expanion-panel
has ViewEncapsulation.None
, Angular won't limit the rule's scope using [_nghost]
/[_ngcontent]
attribute selectors, and Angular will copy the rule into any ShadowDom
-encapsulated components.
This issue was first noted in this comment.
Reproduction
StackBlitz link: https://stackblitz.com/edit/components-issue-bsuofa?file=src%2Fapp%2Fexample-component.ts
Steps to reproduce:
- Observe the animation is janky.
Proof that expansion-panel
is responsible:
- Delete the
<mat-expansion-panel>
element (and its children) fromexample-component.html
. - Reload (to force Angular to clear unused component styles).
- Observe the animation is now smooth.
Proof that the [style]
selector is responsible:
- Right-click > Inspect Element on "expanstion panel contents".
- In DevTools, ensure that
<div class="mat-expansion-panel-body">
is selected. - (optionally) Record a performance trace and observe that "Recalculate Style" affects 10,001 elements and takes a long time.
- Close the expansion panel.
- In DevTools, edit the CSS selector
.mat-expansion-panel-content[style*="visibility: hidden"] *
to remove[style*=...]
- Observe the animation is now smooth.
- (optionally) Record a performance trace and observe that "Recalculate Style" affects 1 element and is very fast.
Expected Behavior
The animation is smooth regardless of if an expansion panel exists or what the expansion panel component does internally.
Actual Behavior
The animation is smooth only after modifying an expansion-panel-internal CSS rule.
Environment
Angular CLI: 16.2.6
Node: 19.9.0 (Unsupported)
Package Manager: npm 9.6.3
OS: linux x64
Angular: 16.2.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1602.6
@angular-devkit/build-angular 16.2.6
@angular-devkit/core 16.2.6
@angular-devkit/schematics 16.2.6
@angular/cdk 16.2.8
@angular/cli 16.2.6
@angular/material 16.2.8
@schematics/angular 16.2.6
rxjs 7.5.7
typescript 5.1.6
zone.js 0.13.3