From b9d3b0aff7b21024784d1bd59ce2df91f56b46f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Thu, 25 May 2023 18:32:26 +0100 Subject: [PATCH] [PM-2398] Fix firefox extension environments bug (#5514) --- .../src/services/config/config.service.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/common/src/services/config/config.service.ts b/libs/common/src/services/config/config.service.ts index f17ded9e6c..dba5d1ca09 100644 --- a/libs/common/src/services/config/config.service.ts +++ b/libs/common/src/services/config/config.service.ts @@ -1,4 +1,5 @@ -import { BehaviorSubject, concatMap, from, timer } from "rxjs"; +import { Injectable, OnDestroy } from "@angular/core"; +import { BehaviorSubject, Subject, concatMap, from, takeUntil, timer } from "rxjs"; import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction"; import { ConfigServiceAbstraction } from "../../abstractions/config/config.service.abstraction"; @@ -10,9 +11,11 @@ import { AuthenticationStatus } from "../../auth/enums/authentication-status"; import { FeatureFlag } from "../../enums/feature-flag.enum"; import { ServerConfigData } from "../../models/data/server-config.data"; -export class ConfigService implements ConfigServiceAbstraction { +@Injectable() +export class ConfigService implements ConfigServiceAbstraction, OnDestroy { protected _serverConfig = new BehaviorSubject(null); serverConfig$ = this._serverConfig.asObservable(); + private destroy$ = new Subject(); constructor( private stateService: StateService, @@ -27,11 +30,14 @@ export class ConfigService implements ConfigServiceAbstraction { this._serverConfig.next(serverConfig); }); - this.environmentService.urls - .pipe(concatMap(() => from(this.fetchServerConfig()))) - .subscribe((serverConfig) => { - this._serverConfig.next(serverConfig); - }); + this.environmentService.urls.pipe(takeUntil(this.destroy$)).subscribe(() => { + this.fetchServerConfig(); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); } async fetchServerConfig(): Promise {