Skip to content

Commit 40a9973

Browse files
committed
fix: Dont render svg if on server-side
1 parent 210780c commit 40a9973

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class AppComponent implements OnInit, OnDestroy {
8181
private publicRoutes = new Set(['/home', '/about', '/login']);
8282
private fullWidthRoutes: string[] = ['/settings', '/stats'];
8383

84-
public showRouterOutlet: boolean = false;
84+
public showRouterOutlet: boolean = true;
8585
public loading: boolean = true;
8686
public pagePath: string = '';
8787
public isFullWidth: boolean = false;

src/app/components/misc/svg-icon.component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Component, Input, OnChanges } from '@angular/core';
1+
import { Component, Inject, Input, OnChanges, PLATFORM_ID } from '@angular/core';
22
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
33
import { Pipe, PipeTransform } from '@angular/core';
4-
import { NgStyle } from '@angular/common';
4+
import { isPlatformBrowser, NgStyle, CommonModule, NgOptimizedImage } from '@angular/common';
55

66
// SafeHtml pipe to bypass Angular's sanitization
77
@Pipe({ name: 'safeHtml', standalone: true })
@@ -16,7 +16,7 @@ export class SafeHtmlPipe implements PipeTransform {
1616
@Component({
1717
selector: 'dl-icon',
1818
standalone: true,
19-
imports: [NgStyle, SafeHtmlPipe],
19+
imports: [NgStyle, SafeHtmlPipe, CommonModule],
2020
template: `
2121
<svg
2222
xmlns="http://www.w3.org/2000/svg"
@@ -27,7 +27,7 @@ export class SafeHtmlPipe implements PipeTransform {
2727
role="img"
2828
focusable="false"
2929
>
30-
<g [innerHTML]="iconSvg | safeHtml"></g>
30+
<g *ngIf="isBrowser" [innerHTML]="iconSvg | safeHtml"></g>
3131
</svg>
3232
`,
3333
})
@@ -41,6 +41,16 @@ export class DlIconComponent implements OnChanges {
4141

4242
mergedStyles: any = {};
4343

44+
isBrowser: boolean = false;
45+
46+
constructor(
47+
@Inject(PLATFORM_ID) private platformId: Object,
48+
) {}
49+
50+
ngOnInit(): void {
51+
this.isBrowser = isPlatformBrowser(this.platformId);
52+
}
53+
4454
ngOnChanges(): void {
4555
// Merge the fill color (defaulting to currentColor) with user-provided styles
4656
this.mergedStyles = {
@@ -172,6 +182,9 @@ export class DlIconComponent implements OnChanges {
172182
* The raw SVG path data (or <path> etc.) for the current icon.
173183
*/
174184
get iconSvg(): string {
185+
if (!isPlatformBrowser(this.platformId)) {
186+
return '';
187+
}
175188
const iconDef = this.icons[this.icon];
176189
if (!iconDef) {
177190
return '';

0 commit comments

Comments
 (0)