Merge pull request #1603 from stackernews/fix-dark-mode-update

Fix missing useDarkMode update
This commit is contained in:
Keyan 2024-11-18 16:09:16 -06:00 committed by GitHub
commit 62cf5b9c34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -48,6 +48,15 @@ const listenForThemeChange = (onChange) => {
onChange({ user: true, dark })
}
}
const root = window.document.documentElement
const observer = new window.MutationObserver(() => {
const theme = root.getAttribute('data-bs-theme')
onChange(dark => ({ ...dark, dark: theme === 'dark' }))
})
observer.observe(root, { attributes: true, attributeFilter: ['data-bs-theme'] })
return () => observer.disconnect()
}
export default function useDarkMode () {