From f22d5ad6836bf694a12fd65641db60bac9ff8f6c Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 3 Mar 2026 19:11:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20storagePersistence=E3=81=AEtop-level=20a?= =?UTF-8?q?wait=E3=82=92=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/boot/common.ts | 5 +++++ packages/frontend/src/utility/storage.ts | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/boot/common.ts b/packages/frontend/src/boot/common.ts index 2b522d3f10..95af48c1db 100644 --- a/packages/frontend/src/boot/common.ts +++ b/packages/frontend/src/boot/common.ts @@ -30,6 +30,7 @@ import { fetchCustomEmojis } from '@/custom-emojis.js'; import { prefer } from '@/preferences.js'; import { $i } from '@/i.js'; import { launchPlugins } from '@/plugin.js'; +import { initializeStoragePersistence } from '@/utility/storage.js'; export async function common(createVue: () => Promise>) { console.info(`Misskey v${version}`); @@ -327,6 +328,10 @@ export async function common(createVue: () => Promise>) { console.error('Failed to launch plugins:', error); } + // ブラウザストレージ永続化の状態を初期化 + // (top-level awaitを防ぐために明示的に起動時に確認する) + initializeStoragePersistence(); + app.mount(rootEl); // boot.jsのやつを解除 diff --git a/packages/frontend/src/utility/storage.ts b/packages/frontend/src/utility/storage.ts index 86f4b8b3c3..5fc56085d6 100644 --- a/packages/frontend/src/utility/storage.ts +++ b/packages/frontend/src/utility/storage.ts @@ -3,20 +3,27 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { ref } from 'vue'; +import { readonly, ref } from 'vue'; import * as os from '@/os.js'; import { store } from '@/store.js'; import { i18n } from '@/i18n.js'; export const storagePersistenceSupported = window.isSecureContext && 'storage' in navigator; -export const storagePersisted = ref(storagePersistenceSupported ? await navigator.storage.persisted() : false); +const _storagePersisted = ref(false); +export const storagePersisted = readonly(_storagePersisted); + +export async function initializeStoragePersistence() { + if (storagePersistenceSupported) { + _storagePersisted.value = await navigator.storage.persisted().catch(() => false); + } +} export async function enableStoragePersistence() { if (!storagePersistenceSupported) return; try { const persisted = await navigator.storage.persist(); if (persisted) { - storagePersisted.value = true; + _storagePersisted.value = true; } else { os.alert({ type: 'error',