@@ -92,7 +92,10 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
92
92
_elementSize = this . _baseSize ;
93
93
94
94
/** Tracks diameters of existing instances to de-dupe generated styles (default d = 100) */
95
- static diameters = new Set < number > ( [ 100 ] ) ;
95
+ private static diameters = new Set < number > ( [ 100 ] ) ;
96
+
97
+ /** Used for storing all of the generated keyframe animations. */
98
+ private static styleTag : HTMLStyleElement ;
96
99
97
100
/** The diameter of the progress spinner (will set width and height of svg). */
98
101
@Input ( )
@@ -130,9 +133,8 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
130
133
131
134
// On IE and Edge, we can't animate the `stroke-dashoffset`
132
135
// reliably so we fall back to a non-spec animation.
133
- const animationClass = this . _fallbackAnimation ?
134
- 'mat-progress-spinner-indeterminate-fallback-animation' :
135
- 'mat-progress-spinner-indeterminate-animation' ;
136
+ const animationClass =
137
+ `mat-progress-spinner-indeterminate${ this . _fallbackAnimation ? '-fallback' : '' } -animation` ;
136
138
137
139
_renderer . addClass ( _elementRef . nativeElement , animationClass ) ;
138
140
}
@@ -183,9 +185,18 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
183
185
184
186
/** Dynamically generates a style tag containing the correct animation for this diameter. */
185
187
private _attachStyleNode ( ) : void {
186
- const styleTag = this . _renderer . createElement ( 'style' ) ;
187
- styleTag . textContent = this . _getAnimationText ( ) ;
188
- this . _renderer . appendChild ( this . _document . head , styleTag ) ;
188
+ let styleTag = MatProgressSpinner . styleTag ;
189
+
190
+ if ( ! styleTag ) {
191
+ styleTag = this . _renderer . createElement ( 'style' ) ;
192
+ this . _renderer . appendChild ( this . _document . head , styleTag ) ;
193
+ MatProgressSpinner . styleTag = styleTag ;
194
+ }
195
+
196
+ if ( styleTag . sheet ) {
197
+ ( styleTag . sheet as CSSStyleSheet ) . insertRule ( this . _getAnimationText ( ) ) ;
198
+ }
199
+
189
200
MatProgressSpinner . diameters . add ( this . diameter ) ;
190
201
}
191
202
0 commit comments