Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions frontend/src/components/Item/Identify/IdentifyDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ const searchFields = computed<IdentifyField[]>(() => {
return result;
});
/**
* TODO: Refactor to remove this use of structuredClone
*/
const fieldsInputs = ref<IdentifyField[]>(
structuredClone(toRaw(searchFields.value))
);
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/plugins/router/middlewares/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type {
RouteMeta
} from 'vue-router';

const defaultMeta: RouteMeta = {
const defaultMeta = (): RouteMeta => ({
layout: {
transition: {}
}
};
});

const reactiveMeta = ref(structuredClone(defaultMeta));
const reactiveMeta = ref(defaultMeta());

/**
* This middleware handles the meta property between routes
Expand Down Expand Up @@ -41,11 +41,11 @@ export function metaGuard(
to: RouteLocationNormalized,
from: RouteLocationNormalized
): NavigationGuardReturn {
reactiveMeta.value = defu(to.meta, structuredClone(defaultMeta));
reactiveMeta.value = defu(to.meta, defaultMeta());
/**
* This is needed to ensure all the meta matches the expected data
*/
from.meta = defu(toRaw(from.meta), structuredClone(defaultMeta));
from.meta = defu(toRaw(from.meta), defaultMeta());
to.meta = reactiveMeta.value;

if (from.meta.layout.transition.leave) {
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/store/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class ApiStore {
/**
* == STATE SECTION ==
*/
/**
* Maps can be cleared (see this._clear), so no need to perform an structuredClone
* of the defaultState here
*/
private readonly _items = reactive(new Map<BaseItemDto['Id'], BaseItemDto>());
private readonly _requests = reactive(new Map<string, Map<string, CachedResponse>>());
public readonly apiEnums = Object.freeze({
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/store/super/common-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Persistence = 'localStorage' | 'sessionStorage';

export abstract class CommonStore<T extends object> {
protected readonly _storeKey: string;
private readonly _defaultState: T;
private readonly _defaultState: () => T;
private readonly _internalState: T | RemovableRef<T>;

protected get _state(): T {
Expand All @@ -20,7 +20,7 @@ export abstract class CommonStore<T extends object> {

protected constructor(storeKey: string, defaultState: T, persistence?: Persistence) {
this._storeKey = storeKey;
this._defaultState = defaultState;
this._defaultState = () => defaultState;

let storage;

Expand All @@ -31,8 +31,8 @@ export abstract class CommonStore<T extends object> {
}

this._internalState = isNil(storage)
? reactive(structuredClone(defaultState)) as T
: useStorage(storeKey, structuredClone(defaultState), storage, {
? reactive(this._defaultState()) as T
: useStorage(storeKey, this._defaultState(), storage, {
mergeDefaults: (storageValue, defaults) =>
mergeExcludingUnknown(storageValue, defaults)
});
Expand Down

0 comments on commit 75f8322

Please sign in to comment.