Fix loading state stuck when API calls fail on startup
Add try/catch to all onMount API calls so the UI recovers gracefully when the server isn't ready yet instead of hanging on the loading skeleton forever. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,9 @@
|
||||
let selectedGroup = $state('');
|
||||
|
||||
onMount(async () => {
|
||||
[categories, groups] = await Promise.all([getCategories(), getGroups()]);
|
||||
try {
|
||||
[categories, groups] = await Promise.all([getCategories(), getGroups()]);
|
||||
} catch { /* server may not be ready yet */ }
|
||||
});
|
||||
|
||||
function handleSearch(e) {
|
||||
|
||||
@@ -7,8 +7,13 @@
|
||||
let syncMessage = $state('');
|
||||
|
||||
onMount(async () => {
|
||||
stores = await getStores();
|
||||
loading = false;
|
||||
try {
|
||||
stores = await getStores();
|
||||
} catch (err) {
|
||||
console.error('Failed to load stores:', err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
|
||||
async function handleToggle(id) {
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
let editingCat = $state(null);
|
||||
|
||||
onMount(async () => {
|
||||
[categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]);
|
||||
loading = false;
|
||||
try {
|
||||
[categories, groups, stores] = await Promise.all([getCategories(), getGroups(), getStores()]);
|
||||
} catch (err) {
|
||||
console.error('Failed to load data:', err);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
|
||||
async function handleAddCategory() {
|
||||
|
||||
Reference in New Issue
Block a user