From c93589be906e9a538f718716007fe0092ec357a0 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 14 Oct 2024 14:21:00 +0200 Subject: [PATCH] fix(admin-ui): Fix theme & ui language switcher Fixes #3111. The recent changes in the data layer introduced this regression. The solution is to internally use a ReplaySubject inside the QueryResult class so that the initial values of any queryRef are always available, even when subscribed _after_ the first value was emitted. --- .../src/lib/core/src/data/query-result.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/admin-ui/src/lib/core/src/data/query-result.ts b/packages/admin-ui/src/lib/core/src/data/query-result.ts index 2512ae9fae..f8087214b8 100644 --- a/packages/admin-ui/src/lib/core/src/data/query-result.ts +++ b/packages/admin-ui/src/lib/core/src/data/query-result.ts @@ -3,7 +3,17 @@ import { notNullOrUndefined } from '@vendure/common/lib/shared-utils'; import { Apollo, QueryRef } from 'apollo-angular'; import { DocumentNode } from 'graphql'; import { merge, Observable, Subject, Subscription } from 'rxjs'; -import { distinctUntilChanged, filter, finalize, map, skip, take, takeUntil } from 'rxjs/operators'; +import { + distinctUntilChanged, + filter, + finalize, + map, + shareReplay, + skip, + startWith, + take, + takeUntil, +} from 'rxjs/operators'; import { CustomFieldConfig, GetUserStatusQuery } from '../common/generated-types'; @@ -194,7 +204,9 @@ export class QueryResult = Record> this.subscribeToQueryRef(this.queryRef); this.queryRefSubscribed.set(this.queryRef, true); } - this.valueChangeSubject.subscribe(subscriber); + this.valueChangeSubject + .pipe(startWith(this.queryRef.getCurrentResult()), shareReplay(1)) + .subscribe(subscriber); return () => { this.queryRefSubscribed.delete(this.queryRef); };