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
|
### Client
|
||||||
-
|
- Fix: ログアウトした際に処理が終了しない問題を修正
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
-
|
-
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
import { apiUrl } from '@@/js/config.js';
|
import { apiUrl } from '@@/js/config.js';
|
||||||
import { defaultMemoryStorage } from '@/memory-storage';
|
import { defaultMemoryStorage } from '@/memory-storage';
|
||||||
import { waiting } from '@/os.js';
|
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';
|
import { $i } from '@/i.js';
|
||||||
|
|
||||||
export async function signout() {
|
export async function signout() {
|
||||||
|
@ -19,13 +20,30 @@ export async function signout() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
defaultMemoryStorage.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);
|
const delidb = indexedDB.deleteDatabase(name);
|
||||||
delidb.onsuccess = () => res();
|
delidb.onsuccess = () => res();
|
||||||
delidb.onerror = e => rej(e);
|
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
|
//#region Remove service worker registration
|
||||||
try {
|
try {
|
||||||
|
@ -50,7 +68,9 @@ export async function signout() {
|
||||||
.then(registrations => {
|
.then(registrations => {
|
||||||
return Promise.all(registrations.map(registration => registration.unregister()));
|
return Promise.all(registrations.map(registration => registration.unregister()));
|
||||||
});
|
});
|
||||||
} catch (err) {}
|
} catch {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
unisonReload('/');
|
unisonReload('/');
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
get as iget,
|
get as iget,
|
||||||
set as iset,
|
set as iset,
|
||||||
del as idel,
|
del as idel,
|
||||||
|
clear as iclear,
|
||||||
} from 'idb-keyval';
|
} from 'idb-keyval';
|
||||||
import { miLocalStorage } from '@/local-storage.js';
|
import { miLocalStorage } from '@/local-storage.js';
|
||||||
|
|
||||||
|
@ -51,3 +52,7 @@ export async function del(key: string) {
|
||||||
if (idbAvailable) return idel(key);
|
if (idbAvailable) return idel(key);
|
||||||
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clear() {
|
||||||
|
if (idbAvailable) return iclear();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue