Fix infinite spinner in offline mode by serializing database operations
- Make onMount await loadLibraryData before starting loadFolders - Add 5-second timeout to loadFolders using Promise.race - Make folder loading non-critical to prevent UI blocking - Prevents database lock deadlock when is_network_path blocks offline
This commit is contained in:
1 parent
2b4b59fc93
commit
e13e5e70e9
1 file changed
+15
-5
@@ -266,9 +266,9 @@
|
||||
previousOfflineState = isOffline;
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
loadLibraryData();
|
||||
loadFolders();
|
||||
onMount(async () => {
|
||||
await loadLibraryData();
|
||||
loadFolders(); // Load in background - doesn't block UI
|
||||
checkDiscogsCredentials();
|
||||
|
||||
// Subscribe to offline state changes
|
||||
@@ -416,7 +416,16 @@
|
||||
|
||||
async function loadFolders() {
|
||||
try {
|
||||
folders = await invoke<LibraryFolder[]>('library_get_folders_with_metadata');
|
||||
console.log('[LocalLibrary] loadFolders START');
|
||||
// Add timeout to prevent infinite hang when offline
|
||||
const timeoutPromise = new Promise<LibraryFolder[]>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Folder loading timeout')), 5000)
|
||||
);
|
||||
const foldersPromise = invoke<LibraryFolder[]>('library_get_folders_with_metadata');
|
||||
|
||||
folders = await Promise.race([foldersPromise, timeoutPromise]);
|
||||
console.log('[LocalLibrary] Received folders:', folders.length);
|
||||
|
||||
// Check accessibility for network folders (skip when offline to avoid hanging)
|
||||
for (const folder of folders) {
|
||||
if (folder.isNetwork) {
|
||||
@@ -433,7 +442,8 @@
|
||||
}
|
||||
folderAccessibility = new Map(folderAccessibility);
|
||||
} catch (err) {
|
||||
console.error('Failed to load folders:', err);
|
||||
console.error('[LocalLibrary] Failed to load folders (timeout or error):', err);
|
||||
// Continue anyway - folders are not critical for basic library functionality
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user