fix: Infinite API request loop on empty stores (#7613)

This commit is contained in:
Michael Genson
2026-05-12 12:25:48 -05:00
committed by GitHub
parent 703db2931f
commit af75c5f39d
12 changed files with 82 additions and 22 deletions

View File

@@ -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();
}