fix(frontend): visibilityStateがhiddenな状態でstartViewTransitionしないように

This commit is contained in:
syuilo 2025-12-01 08:21:30 +09:00 committed by GitHub
parent 128fe6d644
commit e1b6e9d4b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -144,7 +144,9 @@ export function applyTheme(theme: Theme, persist = true) {
if (theme.id === currentThemeId && miLocalStorage.getItem('themeCachedVersion') === version) return; if (theme.id === currentThemeId && miLocalStorage.getItem('themeCachedVersion') === version) return;
currentThemeId = theme.id; currentThemeId = theme.id;
if (window.document.startViewTransition != null) { // visibilityStateがhiddenな状態でstartViewTransitionするとブラウザによってはエラーになる
// 通常hiddenな時に呼ばれることはないが、iOSのPWAだとアプリ切り替え時に(何故か)hiddenな状態で(何故か)一瞬デバイスのダークモード判定が変わりapplyThemeが呼ばれる場合がある
if (window.document.startViewTransition != null && window.document.visibilityState === 'visible') {
window.document.documentElement.classList.add('_themeChanging_'); window.document.documentElement.classList.add('_themeChanging_');
try { try {
window.document.startViewTransition(async () => { window.document.startViewTransition(async () => {