From b761d82d5086836f1a1f401f447e8017c41bc250 Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sat, 20 Jun 2026 12:27:50 +0700 Subject: [PATCH] fix(client): prevent race condition of nested subscriptions --- .../allocations/allocations-page.component.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index f7b9ac314..f265cc8fe 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -43,6 +43,7 @@ import { } from '@prisma/client'; import { isNumber } from 'lodash'; import { DeviceDetectorService } from 'ngx-device-detector'; +import { filter, switchMap, tap } from 'rxjs'; import { AllocationsPageParams } from './interfaces/interfaces'; @@ -161,31 +162,30 @@ export class GfAllocationsPageComponent implements OnInit { }); this.userService.stateChanged - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((state) => { - if (state?.user) { + .pipe( + filter((state) => !!state?.user), + tap((state) => { this.user = state.user; this.isLoading = true; this.initialize(); - this.fetchPortfolioDetails() - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((portfolioDetails) => { - this.initialize(); - - this.portfolioDetails = portfolioDetails; + this.changeDetectorRef.markForCheck(); + }), + switchMap(() => this.fetchPortfolioDetails()), + takeUntilDestroyed(this.destroyRef) + ) + .subscribe((portfolioDetails) => { + this.initialize(); - this.initializeAllocationsData(); + this.portfolioDetails = portfolioDetails; - this.isLoading = false; + this.initializeAllocationsData(); - this.changeDetectorRef.markForCheck(); - }); + this.isLoading = false; - this.changeDetectorRef.markForCheck(); - } + this.changeDetectorRef.markForCheck(); }); this.initialize();