Skip to content

Commit

Permalink
fix: reload preview style error after switching theme (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Feb 11, 2024
1 parent 9e1b761 commit bc4c76c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/output/Preview.vue
Expand Up @@ -49,17 +49,20 @@ watch(
},
)
// reset theme
watch([theme, previewTheme], ([theme, previewTheme]) => {
if (!previewTheme) return
function switchPreviewTheme() {
if (!previewTheme.value) return
const html = sandbox.contentDocument?.documentElement
if (html) {
html.className = theme
html.className = theme.value
} else {
// re-create sandbox
createSandbox()
}
})
}
// reset theme
watch([theme, previewTheme], switchPreviewTheme)
onUnmounted(() => {
proxy.destroy()
Expand Down Expand Up @@ -164,6 +167,7 @@ function createSandbox() {
sandbox.addEventListener('load', () => {
proxy.handle_links()
stopUpdateWatcher = watchEffect(updatePreview)
switchPreviewTheme()
})
}
Expand Down

0 comments on commit bc4c76c

Please sign in to comment.