diff --git a/packages/frontend/src/scripts/note-drafts.ts b/packages/frontend/src/scripts/note-drafts.ts index 958b9ae5dc..67abc004a3 100644 --- a/packages/frontend/src/scripts/note-drafts.ts +++ b/packages/frontend/src/scripts/note-drafts.ts @@ -33,10 +33,11 @@ export async function migrate(userId: string) { if (!raw) return; const drafts = JSON.parse(raw) as Record; + const keys = Object.keys(drafts); const newDrafts: Record = {}; - for (let i = 0; i < Object.keys(drafts).length; i++) { - const key = Object.keys(drafts)[i]; + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; const [type, id] = key.split(':'); if (type === 'note' && id !== userId) continue; const keyType = type === 'renote' ? 'quote' : type as keyof NoteKeys; @@ -52,6 +53,7 @@ export async function migrate(userId: string) { delete drafts[key]; } + if (Object.keys(newDrafts).length === 0) return; await idbSet(`drafts::${userId}`, newDrafts); miLocalStorage.setItem('drafts', JSON.stringify(drafts)); } @@ -71,8 +73,8 @@ export async function getAll(userId: string) { export async function get(type: T, userId: string, uniqueId: string, ...args: Parameters) { const key = getKey(type, uniqueId, ...args); - const draft = await getAll(userId)[key]; - return draft ?? null; + const draft = await getAll(userId); + return draft[key] ?? null; } export async function set(type: T, userId: string, uniqueId: string, draft: NoteDraft['data'], ...args: Parameters) {