Skip to content

Commit 30d93d2

Browse files
authored
Merge pull request #10611 from IgniteUI/simeonoff/icon-service-ssr
fix(icon-service): don't initialize DOMParser in SSR mode
2 parents bb2b998 + 47827b9 commit 30d93d2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('igxCombo', () => {
9595
get: mockNgControl
9696
});
9797
mockSelection.get.and.returnValue(new Set([]));
98-
const mockIconService = new IgxIconService(null, null, null);
98+
const mockIconService = new IgxIconService(null, null, null, null);
9999
it('should correctly implement interface methods - ControlValueAccessor ', () => {
100100
combo = new IgxComboComponent(elementRef, mockCdr, mockSelection as any, mockComboService,
101101
mockIconService, null, null, mockInjector);

projects/igniteui-angular/src/lib/icon/icon.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
33
import { DOCUMENT } from '@angular/common';
44
import { HttpClient } from '@angular/common/http';
55
import { Observable, Subject } from 'rxjs';
6+
import { PlatformUtil } from '../core/utils';
67

78
/**
89
* Event emitted when a SVG icon is loaded through
@@ -48,14 +49,19 @@ export class IgxIconService {
4849
private _familyAliases = new Map<string, string>();
4950
private _cachedSvgIcons = new Map<string, Map<string, SafeHtml>>();
5051
private _iconLoaded = new Subject<IgxIconLoadedEvent>();
51-
private _domParser = new DOMParser();
52+
private _domParser: DOMParser;
5253

5354
constructor(
5455
@Optional() private _sanitizer: DomSanitizer,
5556
@Optional() private _httpClient: HttpClient,
56-
@Optional() @Inject(DOCUMENT) private _document: any
57+
@Optional() private _platformUtil: PlatformUtil,
58+
@Optional() @Inject(DOCUMENT) private _document: any,
5759
) {
5860
this.iconLoaded = this._iconLoaded.asObservable();
61+
62+
if(this._platformUtil?.isBrowser) {
63+
this._domParser = new DOMParser();
64+
}
5965
}
6066

6167
/**
@@ -188,7 +194,7 @@ export class IgxIconService {
188194
private cacheSvgIcon(name: string, value: string, family = this._family, stripMeta: boolean) {
189195
family = !!family ? family : this._family;
190196

191-
if (name && value) {
197+
if (this._platformUtil?.isBrowser && name && value) {
192198
const doc = this._domParser.parseFromString(value, 'image/svg+xml');
193199
const svg = doc.querySelector('svg') as SVGElement;
194200

0 commit comments

Comments
 (0)