@@ -263,8 +263,15 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
263
263
} ,
264
264
notifyTrailingIconInteraction : ( ) => this . removeIconInteraction . emit ( this . id ) ,
265
265
notifyRemoval : ( ) => this . removed . emit ( { chip : this } ) ,
266
- getComputedStyleValue : propertyName =>
267
- window . getComputedStyle ( this . _elementRef . nativeElement ) . getPropertyValue ( propertyName ) ,
266
+ getComputedStyleValue : propertyName => {
267
+ // This function is run when a chip is removed so it might be
268
+ // invoked during server-side rendering. Add some extra checks just in case.
269
+ if ( typeof window !== 'undefined' && window ) {
270
+ const getComputedStyle = window . getComputedStyle ( this . _elementRef . nativeElement ) ;
271
+ return getComputedStyle . getPropertyValue ( propertyName ) ;
272
+ }
273
+ return '' ;
274
+ } ,
268
275
setStyleProperty : ( propertyName : string , value : string ) => {
269
276
this . _elementRef . nativeElement . style . setProperty ( propertyName , value ) ;
270
277
} ,
@@ -339,12 +346,13 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
339
346
_listenToRemoveIconInteraction ( ) {
340
347
this . removeIcon . interaction
341
348
. pipe ( takeUntil ( this . _destroyed ) )
342
- . subscribe ( ( event ) => {
349
+ . subscribe ( event => {
343
350
// The MDC chip foundation calls stopPropagation() for any trailing icon interaction
344
351
// event, even ones it doesn't handle, so we want to avoid passing it keyboard events
345
- // for which we have a custom handler.
346
- if ( this . disabled || ( event instanceof KeyboardEvent &&
347
- this . HANDLED_KEYS . indexOf ( event . keyCode ) !== - 1 ) ) {
352
+ // for which we have a custom handler. Note that we assert the type of the event using
353
+ // the `type`, because `instanceof KeyboardEvent` can throw during server-side rendering.
354
+ if ( this . disabled || ( event . type . startsWith ( 'key' ) &&
355
+ this . HANDLED_KEYS . indexOf ( ( event as KeyboardEvent ) . keyCode ) !== - 1 ) ) {
348
356
return ;
349
357
}
350
358
this . _chipFoundation . handleTrailingIconInteraction ( event ) ;
0 commit comments