nanostores/query

fetcherStore.fetch promise will never be resolved when the data is empty

BrRenat opened this issue · 4 comments

query/lib/factory.ts

Lines 299 to 307 in ac92fa1

fetcherStore.fetch = async () => {
let resolve: (value: LazyFetchValue) => void;
const promise = new Promise<LazyFetchValue>((r) => (resolve = r));
const unsub = fetcherStore.listen(({ error, data }) => {
if (error) resolve({ error });
if (data) resolve({ data });
});
return promise.finally(unsub);
};

ac92fa1#r143713277

If the data is undefined or zero or empty string and etc, your promise will fail on timeout. To ensure that we don't wait for the API response, we should add a check for the loading property.

Sorry, the error has not occurred, but promise will never be resolved