From 96525acd6771a853cd55aeb172778fb91808245a Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Sat, 17 Aug 2024 16:46:09 +0200 Subject: [PATCH] fix: don't freeze on falsesy values in useData --- frontend/src/composables/useData.ts | 3 ++- frontend/src/composables/useDataLoader.ts | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frontend/src/composables/useData.ts b/frontend/src/composables/useData.ts index 16310e236..210cfe495 100644 --- a/frontend/src/composables/useData.ts +++ b/frontend/src/composables/useData.ts @@ -25,7 +25,8 @@ import type { SettingsResponse, User, VersionInfo, - Platform } from "~/types/backend"; + Platform, +} from "~/types/backend"; export function useOrganizationVisibility(user: () => string) { const { data: organizationVisibility, status: organizationVisibilityStatus } = useData( diff --git a/frontend/src/composables/useDataLoader.ts b/frontend/src/composables/useDataLoader.ts index 83761ac59..db0ef02d2 100644 --- a/frontend/src/composables/useDataLoader.ts +++ b/frontend/src/composables/useDataLoader.ts @@ -79,6 +79,7 @@ export function useData | string>( let promise: Promise | undefined; function refresh() { + console.log("refresh", key(params())); return load(params()); } @@ -103,16 +104,18 @@ export function useData | string>( // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { console.log("load", key(params)); - const result = await loader(params).catch(reject); - // await new Promise((resolve) => setTimeout(resolve, 5000)); - console.log("loaded", key(params)); - if (result) { + try { + const result = await loader(params); + // await new Promise((resolve) => setTimeout(resolve, 5000)); + console.log("loaded", key(params)); setState(result); status.value = "success"; callback(params); resolve(); - } else { + } catch (err) { status.value = "error"; + callback(params); + reject(err); } }); } @@ -128,6 +131,7 @@ export function useData | string>( onServerPrefetch(async () => { console.log("server prefetch", key(params())); await promise; + console.log("server prefetch done", key(params())); }); } }