Skip to content

Commit 86b4ce2

Browse files
committed
119602: Fix SSR error by making klaroService optional
KlaroService handles cookies which are not applicable during SSR. By making the service optional, and handling the case when it is not available, SSR can do its work without throwing NullInjectorErrors.
1 parent 9070ad6 commit 86b4ce2

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/app/info/accessibility-settings/accessibility-settings.component.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Component,
44
OnDestroy,
55
OnInit,
6+
Optional,
67
} from '@angular/core';
78
import { FormsModule } from '@angular/forms';
89
import {
@@ -30,7 +31,10 @@ import { AuthService } from '../../core/auth/auth.service';
3031
import { AlertComponent } from '../../shared/alert/alert.component';
3132
import { ContextHelpDirective } from '../../shared/context-help.directive';
3233
import { KlaroService } from '../../shared/cookies/klaro.service';
33-
import { isEmpty } from '../../shared/empty.util';
34+
import {
35+
hasValue,
36+
isEmpty,
37+
} from '../../shared/empty.util';
3438
import { NotificationsService } from '../../shared/notifications/notifications.service';
3539

3640
/**
@@ -65,7 +69,7 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
6569
protected settingsService: AccessibilitySettingsService,
6670
protected notificationsService: NotificationsService,
6771
protected translateService: TranslateService,
68-
protected klaroService: KlaroService,
72+
@Optional() protected klaroService: KlaroService,
6973
) {
7074
}
7175

@@ -75,11 +79,19 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
7579
this.subscriptions.push(
7680
this.authService.isAuthenticated().pipe(distinctUntilChanged())
7781
.subscribe(val => this.isAuthenticated.next(val)),
78-
this.klaroService.getSavedPreferences().pipe(
79-
map(preferences => preferences?.accessibility === true),
80-
distinctUntilChanged(),
81-
).subscribe(val => this.cookieIsAccepted.next(val)),
8282
);
83+
84+
if (hasValue(this.klaroService)) {
85+
this.subscriptions.push(
86+
this.klaroService.getSavedPreferences().pipe(
87+
map(preferences => preferences?.accessibility === true),
88+
distinctUntilChanged(),
89+
).subscribe(val => this.cookieIsAccepted.next(val)),
90+
);
91+
} else {
92+
this.cookieIsAccepted.next(false);
93+
}
94+
8395
}
8496

8597
ngOnDestroy() {

0 commit comments

Comments
 (0)