fix(frontend): keyval-storeの値が削除できずに処理が止まる問題を修正 (#15803)
* fix(frontend): keyval-storeの値が削除できずに処理が止まる問題を修正 * Update Changelog * implement abortcontroller * fix lint
This commit is contained in:
parent
81bf139e3e
commit
dd5dd6184a
|
@ -4,7 +4,7 @@
|
|||
-
|
||||
|
||||
### Client
|
||||
-
|
||||
- Fix: ログアウトした際に処理が終了しない問題を修正
|
||||
|
||||
### Server
|
||||
-
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
import { apiUrl } from '@@/js/config.js';
|
||||
import { defaultMemoryStorage } from '@/memory-storage';
|
||||
import { waiting } from '@/os.js';
|
||||
import { unisonReload, reloadChannel } from '@/utility/unison-reload.js';
|
||||
import { unisonReload } from '@/utility/unison-reload.js';
|
||||
import { clear } from '@/utility/idb-proxy.js';
|
||||
import { $i } from '@/i.js';
|
||||
|
||||
export async function signout() {
|
||||
|
@ -19,13 +20,30 @@ export async function signout() {
|
|||
localStorage.clear();
|
||||
defaultMemoryStorage.clear();
|
||||
|
||||
const idbPromises = ['MisskeyClient', 'keyval-store'].map((name, i, arr) => new Promise<void>((res, rej) => {
|
||||
const idbAbortController = new AbortController();
|
||||
const timeout = window.setTimeout(() => idbAbortController.abort(), 5000);
|
||||
|
||||
const idbPromises = ['MisskeyClient'].map((name, i, arr) => new Promise<void>((res, rej) => {
|
||||
const delidb = indexedDB.deleteDatabase(name);
|
||||
delidb.onsuccess = () => res();
|
||||
delidb.onerror = e => rej(e);
|
||||
delidb.onblocked = () => idbAbortController.signal.aborted && rej(new Error('Operation aborted'));
|
||||
}));
|
||||
|
||||
await Promise.all(idbPromises);
|
||||
try {
|
||||
await Promise.race([
|
||||
Promise.all([
|
||||
...idbPromises,
|
||||
// idb keyval-storeはidb-keyvalライブラリによる別管理
|
||||
clear(),
|
||||
]),
|
||||
new Promise((_, rej) => idbAbortController.signal.addEventListener('abort', () => rej(new Error('Operation timed out')))),
|
||||
]);
|
||||
} catch {
|
||||
// nothing
|
||||
} finally {
|
||||
window.clearTimeout(timeout);
|
||||
}
|
||||
|
||||
//#region Remove service worker registration
|
||||
try {
|
||||
|
@ -50,7 +68,9 @@ export async function signout() {
|
|||
.then(registrations => {
|
||||
return Promise.all(registrations.map(registration => registration.unregister()));
|
||||
});
|
||||
} catch (err) {}
|
||||
} catch {
|
||||
// nothing
|
||||
}
|
||||
//#endregion
|
||||
|
||||
unisonReload('/');
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
get as iget,
|
||||
set as iset,
|
||||
del as idel,
|
||||
clear as iclear,
|
||||
} from 'idb-keyval';
|
||||
import { miLocalStorage } from '@/local-storage.js';
|
||||
|
||||
|
@ -51,3 +52,7 @@ export async function del(key: string) {
|
|||
if (idbAvailable) return idel(key);
|
||||
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
||||
}
|
||||
|
||||
export async function clear() {
|
||||
if (idbAvailable) return iclear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue