From e00e7a1f0e0ccbbc56dfaa1227bef25f5a4aaba0 Mon Sep 17 00:00:00 2001 From: Wagner Maciel Date: Mon, 24 Aug 2020 10:27:37 -0700 Subject: [PATCH 1/2] revert(mat-icon): this reverts two files from commit 79e4d28 * These checks caused failures in pantheon where icons were not loading --- src/material/icon/icon-registry.ts | 29 +++++++++++++++++------------ src/material/icon/icon.ts | 6 +----- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/material/icon/icon-registry.ts b/src/material/icon/icon-registry.ts index 711bedb1998b..6696c8900f48 100644 --- a/src/material/icon/icon-registry.ts +++ b/src/material/icon/icon-registry.ts @@ -175,7 +175,8 @@ export class MatIconRegistry implements OnDestroy { options?: IconOptions): this { const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal); - if (!cleanLiteral && (typeof ngDevMode === 'undefined' || ngDevMode)) { + // TODO: add an ngDevMode check + if (!cleanLiteral) { throw getMatIconFailedToSanitizeLiteralError(literal); } @@ -217,7 +218,7 @@ export class MatIconRegistry implements OnDestroy { options?: IconOptions): this { const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal); - if (!cleanLiteral && (typeof ngDevMode === 'undefined' || ngDevMode)) { + if (!cleanLiteral) { throw getMatIconFailedToSanitizeLiteralError(literal); } @@ -381,11 +382,12 @@ export class MatIconRegistry implements OnDestroy { return forkJoin(iconSetFetchRequests).pipe(map(() => { const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs); - if (!foundIcon && (typeof ngDevMode === 'undefined' || ngDevMode)) { + // TODO: add an ngDevMode check + if (!foundIcon) { throw getMatIconNameNotFoundError(name); } - return foundIcon!; + return foundIcon; })); } @@ -491,7 +493,8 @@ export class MatIconRegistry implements OnDestroy { div.innerHTML = str; const svg = div.querySelector('svg') as SVGElement; - if (!svg && (typeof ngDevMode === 'undefined' || ngDevMode)) { + // TODO: add an ngDevMode check + if (!svg) { throw Error(' tag not found'); } @@ -552,31 +555,33 @@ export class MatIconRegistry implements OnDestroy { throw getMatIconNoHttpProviderError(); } - if (safeUrl == null && (typeof ngDevMode === 'undefined' || ngDevMode)) { + // TODO: add an ngDevMode check + if (safeUrl == null) { throw Error(`Cannot fetch icon from URL "${safeUrl}".`); } const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl); - if (!url && (typeof ngDevMode === 'undefined' || ngDevMode)) { - throw getMatIconFailedToSanitizeUrlError(safeUrl!); + // TODO: add an ngDevMode check + if (!url) { + throw getMatIconFailedToSanitizeUrlError(safeUrl); } // Store in-progress fetches to avoid sending a duplicate request for a URL when there is // already a request in progress for that URL. It's necessary to call share() on the // Observable returned by http.get() so that multiple subscribers don't cause multiple XHRs. - const inProgressFetch = this._inProgressUrlFetches.get(url!); + const inProgressFetch = this._inProgressUrlFetches.get(url); if (inProgressFetch) { return inProgressFetch; } - const req = this._httpClient.get(url!, {responseType: 'text', withCredentials}).pipe( - finalize(() => this._inProgressUrlFetches.delete(url!)), + const req = this._httpClient.get(url, {responseType: 'text', withCredentials}).pipe( + finalize(() => this._inProgressUrlFetches.delete(url)), share(), ); - this._inProgressUrlFetches.set(url!, req); + this._inProgressUrlFetches.set(url, req); return req; } diff --git a/src/material/icon/icon.ts b/src/material/icon/icon.ts index 173b11893810..cc0892c5f1d9 100644 --- a/src/material/icon/icon.ts +++ b/src/material/icon/icon.ts @@ -222,11 +222,7 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft switch (parts.length) { case 1: return ['', parts[0]]; // Use default namespace. case 2: return <[string, string]>parts; - default: - if (typeof ngDevMode === 'undefined' || ngDevMode) { - throw Error(`Invalid icon name: "${iconName}"`); - } - return ['', '']; + default: throw Error(`Invalid icon name: "${iconName}"`); // TODO: add an ngDevMode check } } From 5552abe7987a62536546563c2ee2227a058495f8 Mon Sep 17 00:00:00 2001 From: Wagner Maciel Date: Mon, 24 Aug 2020 10:30:40 -0700 Subject: [PATCH 2/2] fix(form-field): add a type check for userAriaDescribedBy * Internal test was failing because userAriaDescribedBy showed up as an object so calling .split was throwing errors. --- src/material-experimental/mdc-form-field/form-field.ts | 4 +++- src/material/form-field/form-field.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/material-experimental/mdc-form-field/form-field.ts b/src/material-experimental/mdc-form-field/form-field.ts index 5c082fb9133c..9dcee42cb5e1 100644 --- a/src/material-experimental/mdc-form-field/form-field.ts +++ b/src/material-experimental/mdc-form-field/form-field.ts @@ -584,7 +584,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck if (this._control) { let ids: string[] = []; - if (this._control.userAriaDescribedBy) { + // TODO(wagnermaciel): Remove the type check when we find the root cause of this bug. + if (this._control.userAriaDescribedBy && + typeof this._control.userAriaDescribedBy === 'string') { ids.push(...this._control.userAriaDescribedBy.split(' ')); } diff --git a/src/material/form-field/form-field.ts b/src/material/form-field/form-field.ts index 398aab49a123..738ce559dcde 100644 --- a/src/material/form-field/form-field.ts +++ b/src/material/form-field/form-field.ts @@ -507,7 +507,9 @@ export class MatFormField extends _MatFormFieldMixinBase if (this._control) { let ids: string[] = []; - if (this._control.userAriaDescribedBy) { + // TODO(wagnermaciel): Remove the type check when we find the root cause of this bug. + if (this._control.userAriaDescribedBy && + typeof this._control.userAriaDescribedBy === 'string') { ids.push(...this._control.userAriaDescribedBy.split(' ')); }