Skip to content

Commit b0c1a16

Browse files
committed
fix: ensure the user configuration is only loaded once
1 parent 5a214ca commit b0c1a16

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/packages/core/store/store-object-base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
88
* The base class for a store that holds an object.
99
*/
1010
export class UmbStoreObjectBase<T> extends UmbContextBase<never> implements UmbApi {
11-
protected _data: UmbObjectState<T>;
11+
protected _data: UmbObjectState<T | undefined>;
1212

1313
constructor(host: UmbControllerHost, storeAlias: string, initialData?: T) {
1414
super(host, storeAlias);
15-
this._data = new UmbObjectState(initialData ?? ({} as T));
15+
this._data = new UmbObjectState(initialData);
1616
}
1717

1818
/**
@@ -29,7 +29,7 @@ export class UmbStoreObjectBase<T> extends UmbContextBase<never> implements UmbA
2929
* Returns the current state of the store
3030
* @memberof UmbStoreObjectBase
3131
*/
32-
getState(): T {
32+
getState(): T | undefined {
3333
return this._data.getValue();
3434
}
3535

@@ -47,7 +47,7 @@ export class UmbStoreObjectBase<T> extends UmbContextBase<never> implements UmbA
4747
* @memberof UmbStoreObjectBase
4848
*/
4949
part<Part extends keyof T>(key: Part): Observable<T[Part]> {
50-
return this._data.asObservablePart((data) => data[key]);
50+
return this._data.asObservablePart((data) => data![key]);
5151
}
5252

5353
/**

src/packages/user/user/repository/config/user-config.repository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export class UmbUserConfigRepository extends UmbRepositoryBase implements UmbApi
1919
}
2020

2121
async #init() {
22+
// Check if the store already has data
23+
if (this.#dataStore?.getState()) {
24+
return;
25+
}
26+
2227
const { data } = await this.#dataSource.getUserConfig();
2328

2429
if (data) {

0 commit comments

Comments
 (0)