mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-14 05:47:28 -04:00
fix: Infinite API request loop on empty stores (#7613)
This commit is contained in:
@@ -16,10 +16,11 @@ export const useReadOnlyStore = function <T extends BoundT>(
|
||||
storeKey: string,
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
initialized: Ref<boolean>,
|
||||
api: BaseCRUDAPIReadOnly<T>,
|
||||
params = {} as Record<string, QueryValue>,
|
||||
) {
|
||||
const storeActions = useReadOnlyActions(`${storeKey}-store-readonly`, api, store, loading);
|
||||
const storeActions = useReadOnlyActions(`${storeKey}-store-readonly`, api, store, loading, initialized);
|
||||
const actions = {
|
||||
...storeActions,
|
||||
async refresh() {
|
||||
@@ -27,11 +28,12 @@ export const useReadOnlyStore = function <T extends BoundT>(
|
||||
},
|
||||
flushStore() {
|
||||
store.value = [];
|
||||
initialized.value = false;
|
||||
},
|
||||
};
|
||||
|
||||
// initial hydration
|
||||
if (!loading.value && !store.value.length) {
|
||||
if (!loading.value && !initialized.value) {
|
||||
actions.refresh();
|
||||
}
|
||||
|
||||
@@ -42,10 +44,11 @@ export const useStore = function <T extends BoundT>(
|
||||
storeKey: string,
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
initialized: Ref<boolean>,
|
||||
api: BaseCRUDAPI<unknown, T, unknown>,
|
||||
params = {} as Record<string, QueryValue>,
|
||||
) {
|
||||
const storeActions = useStoreActions(`${storeKey}-store`, api, store, loading);
|
||||
const storeActions = useStoreActions(`${storeKey}-store`, api, store, loading, initialized);
|
||||
const actions = {
|
||||
...storeActions,
|
||||
async refresh() {
|
||||
@@ -53,11 +56,12 @@ export const useStore = function <T extends BoundT>(
|
||||
},
|
||||
flushStore() {
|
||||
store.value = [];
|
||||
initialized.value = false;
|
||||
},
|
||||
};
|
||||
|
||||
// initial hydration
|
||||
if (!loading.value && !store.value.length) {
|
||||
if (!loading.value && !initialized.value) {
|
||||
actions.refresh();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user