fix: harden persistence checks and export timeout

This commit is contained in:
dayuan.jiang
2026-01-25 14:33:20 +09:00
parent 384221c498
commit 7525253499
3 changed files with 26 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ import {
} from "@/components/ui/resizable"
import { useDiagram } from "@/contexts/diagram-context"
import { i18n, type Locale } from "@/lib/i18n/config"
import { isIndexedDBAvailable } from "@/lib/session-storage"
import { isIndexedDBUsable } from "@/lib/session-storage"
export default function Home() {
const {
@@ -83,7 +83,10 @@ export default function Home() {
setDrawioBaseUrl(`${window.location.origin}/drawio/index.html`)
}
setCanPersist(isIndexedDBAvailable())
void (async () => {
const usable = await isIndexedDBUsable()
setCanPersist(usable)
})()
setIsLoaded(true)
}, [pathname, router])

View File

@@ -144,17 +144,15 @@ export default function ChatPanel({
handleExportWithoutHistory()
}
}),
new Promise<string>((_, reject) =>
setTimeout(
() =>
reject(
new Error(
"Chart export timed out after 10 seconds",
),
),
10000,
),
),
new Promise<string>((_, reject) => {
const currentResolver = resolverRef.current
setTimeout(() => {
if (resolverRef.current === currentResolver) {
resolverRef.current = null
}
reject(new Error("Chart export timed out after 10 seconds"))
}, 10000)
}),
])
}

View File

@@ -75,6 +75,18 @@ export function isIndexedDBAvailable(): boolean {
}
}
// Check if IndexedDB is actually usable (not just present).
export async function isIndexedDBUsable(): Promise<boolean> {
if (!isIndexedDBAvailable()) return false
try {
const db = await getDB()
db.close()
return true
} catch {
return false
}
}
// CRUD Operations
export async function getAllSessionMetadata(): Promise<SessionMetadata[]> {
if (!isIndexedDBAvailable()) return []