Fix hydration issue + Edit Page (#1043)

This commit is contained in:
Geometrically
2023-03-12 13:00:09 -07:00
committed by GitHub
parent 130ece3d2e
commit 6d9779a497
5 changed files with 32 additions and 26 deletions

25
plugins/1.theme.js Normal file
View File

@@ -0,0 +1,25 @@
export default defineNuxtPlugin((nuxtApp) => {
const themeStore = useTheme()
// TODO: Temporarily removed as it was causing hydration issues
// nuxtApp.hook('app:mounted', () => {
// if (process.client && themeStore.value.preference === 'system') {
// const colorSchemeQueryList = window.matchMedia('(prefers-color-scheme: light)')
//
// const setColorScheme = (e) => {
// if (themeStore.value.preference === 'system') {
// if (e.matches) {
// updateTheme('light')
// } else {
// updateTheme('dark')
// }
// }
// }
//
// setColorScheme(colorSchemeQueryList)
// colorSchemeQueryList.addEventListener('change', setColorScheme)
// }
// })
nuxtApp.provide('colorMode', themeStore.value)
})

View File

@@ -1,24 +0,0 @@
export default defineNuxtPlugin((nuxtApp) => {
const themeStore = useTheme()
if (process.client && themeStore.value.preference === 'system') {
setTimeout(() => {
const colorSchemeQueryList = window.matchMedia('(prefers-color-scheme: light)')
const setColorScheme = (e) => {
if (themeStore.value.preference === 'system') {
if (e.matches) {
updateTheme('light')
} else {
updateTheme('dark')
}
}
}
setColorScheme(colorSchemeQueryList)
colorSchemeQueryList.addEventListener('change', setColorScheme)
}, 100)
}
nuxtApp.provide('colorMode', themeStore.value)
})