fix(library): keep the shell the deploy replaced out of a failed navigation, and say when another tab holds the library open

This commit is contained in:
2026-10-08 09:23:23 +07:00
parent a3bb412070
commit cda08c3908
5 changed files with 62 additions and 7 deletions
+13
View File
@@ -213,9 +213,21 @@ async function migrateLegacyDatabase(db: IDBDatabase): Promise<void> {
let dbPromise: Promise<IDBDatabase> | null = null;
// One library database per browser, so every tab shares it — and a tab left open
// across a build holds it at the version it was opened with. The browser answers
// the newer tab's open with silence until that tab goes: no error, no rows, no
// note, a LIBRARY that has simply not loaded and never says why. The wait is
// reported instead, and it ends by itself when the other tab is closed or reloaded.
let blockedSink: ((blocked: boolean) => void) | null = null;
export function onLibraryBlocked(fn: ((blocked: boolean) => void) | null): void {
blockedSink = fn;
}
function openDb(): Promise<IDBDatabase> {
dbPromise ??= new Promise<IDBDatabase>((resolve, reject) => {
const req = indexedDB.open(DB_NAME, DB_VERSION);
req.onblocked = () => blockedSink?.(true);
req.onupgradeneeded = () => {
const db = req.result;
if (!db.objectStoreNames.contains(FOLDERS)) db.createObjectStore(FOLDERS, { keyPath: 'name' });
@@ -230,6 +242,7 @@ function openDb(): Promise<IDBDatabase> {
if (!db.objectStoreNames.contains(EDITS)) db.createObjectStore(EDITS, { keyPath: 'photoId' });
};
req.onsuccess = () => {
blockedSink?.(false);
const db = req.result;
void migrateLegacyDatabase(db).then(() => resolve(db));
};