@@ -263,8 +263,15 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
263263 } ,
264264 notifyTrailingIconInteraction : ( ) => this . removeIconInteraction . emit ( this . id ) ,
265265 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+ } ,
268275 setStyleProperty : ( propertyName : string , value : string ) => {
269276 this . _elementRef . nativeElement . style . setProperty ( propertyName , value ) ;
270277 } ,
@@ -339,12 +346,13 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
339346 _listenToRemoveIconInteraction ( ) {
340347 this . removeIcon . interaction
341348 . pipe ( takeUntil ( this . _destroyed ) )
342- . subscribe ( ( event ) => {
349+ . subscribe ( event => {
343350 // The MDC chip foundation calls stopPropagation() for any trailing icon interaction
344351 // 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 ) ) {
348356 return ;
349357 }
350358 this . _chipFoundation . handleTrailingIconInteraction ( event ) ;
0 commit comments