Skip to content

Commit 96cb174

Browse files
authored
chore(intranet-header-workspace): fix intranet-header mutationObserver error (#4824)
1 parent 92babaf commit 96cb174

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.changeset/spotty-lizards-design.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@swisspost/design-system-intranet-header': patch
3+
---
4+
5+
Updated the `Intranet-Header` to run `mutationObserver` only when navigation is present and to detect changes `onAfterViewInit`.

packages/intranet-header-workspace/projects/intranet-header/src/lib/swisspost-intranet-header.component.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
SecurityContext,
1111
TemplateRef,
1212
ViewChild,
13+
ChangeDetectorRef,
1314
} from '@angular/core';
1415
import { DomSanitizer } from '@angular/platform-browser';
1516
import { NavigationStart, Router } from '@angular/router';
@@ -91,6 +92,7 @@ export class SwissPostIntranetHeaderComponent implements OnInit, AfterViewInit {
9192
private router: Router,
9293
private zone: NgZone,
9394
private domSanitizer: DomSanitizer,
95+
private cd: ChangeDetectorRef,
9496
) {
9597
this.router.events.subscribe(e => {
9698
if (e instanceof NavigationStart) {
@@ -142,12 +144,14 @@ export class SwissPostIntranetHeaderComponent implements OnInit, AfterViewInit {
142144

143145
if (!MutationObserver) return;
144146

145-
this.navChanges = new MutationObserver(m => this.navMutationCallback(m));
146-
this.navChanges.observe(this.navElement, {
147-
childList: true,
148-
characterData: true,
149-
subtree: true,
150-
});
147+
if (this.navElement) {
148+
this.navChanges = new MutationObserver(m => this.navMutationCallback(m));
149+
this.navChanges.observe(this.navElement, {
150+
childList: true,
151+
characterData: true,
152+
subtree: true,
153+
});
154+
}
151155
}
152156

153157
this.optionDropdownClick();
@@ -157,6 +161,8 @@ export class SwissPostIntranetHeaderComponent implements OnInit, AfterViewInit {
157161
subtree: true,
158162
childList: true,
159163
});
164+
165+
this.cd.detectChanges();
160166
}
161167

162168
public navMutationCallback(mutationList: MutationRecord[]) {

0 commit comments

Comments
 (0)