From c6ef2467bc3aba93101fb614e82ace6990e970bd Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Tue, 1 Jul 2025 09:06:40 +0200 Subject: [PATCH] 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. --- .../accessibility-settings.component.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.ts b/src/app/info/accessibility-settings/accessibility-settings.component.ts index 28e3729552..9c70c05a94 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit, Optional } from '@angular/core'; import { AuthService } from '../../core/auth/auth.service'; import { AccessibilitySetting, @@ -8,7 +8,7 @@ import { import { BehaviorSubject, distinctUntilChanged, map, Subscription, take } from 'rxjs'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; -import { isEmpty } from 'src/app/shared/empty.util'; +import { hasValue, isEmpty } from 'src/app/shared/empty.util'; import { AlertType } from '../../shared/alert/alert-type'; import { KlaroService } from '../../shared/cookies/klaro.service'; @@ -35,7 +35,7 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy { protected settingsService: AccessibilitySettingsService, protected notificationsService: NotificationsService, protected translateService: TranslateService, - protected klaroService: KlaroService, + @Optional() protected klaroService: KlaroService, ) { } @@ -45,11 +45,19 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy { this.subscriptions.push( this.authService.isAuthenticated().pipe(distinctUntilChanged()) .subscribe(val => this.isAuthenticated.next(val)), - this.klaroService.getSavedPreferences().pipe( - map(preferences => preferences?.accessibility === true), - distinctUntilChanged(), - ).subscribe(val => this.cookieIsAccepted.next(val)), ); + + if (hasValue(this.klaroService)) { + this.subscriptions.push( + this.klaroService.getSavedPreferences().pipe( + map(preferences => preferences?.accessibility === true), + distinctUntilChanged(), + ).subscribe(val => this.cookieIsAccepted.next(val)) + ); + } else { + this.cookieIsAccepted.next(false); + } + } ngOnDestroy() {