Browse Source

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.
Michael Bromley 1 year ago
parent
commit
c93589be90
1 changed files with 14 additions and 2 deletions
  1. 14 2
      packages/admin-ui/src/lib/core/src/data/query-result.ts

+ 14 - 2
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<T, V extends Record<string, any> = Record<string, any>>
                 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);
             };