Skip to content

Commit bc4c76c

Browse files
authored
fix: reload preview style error after switching theme (#214)
1 parent 9e1b761 commit bc4c76c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/output/Preview.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ watch(
4949
},
5050
)
5151
52-
// reset theme
53-
watch([theme, previewTheme], ([theme, previewTheme]) => {
54-
if (!previewTheme) return
52+
function switchPreviewTheme() {
53+
if (!previewTheme.value) return
5554
5655
const html = sandbox.contentDocument?.documentElement
5756
if (html) {
58-
html.className = theme
57+
html.className = theme.value
5958
} else {
59+
// re-create sandbox
6060
createSandbox()
6161
}
62-
})
62+
}
63+
64+
// reset theme
65+
watch([theme, previewTheme], switchPreviewTheme)
6366
6467
onUnmounted(() => {
6568
proxy.destroy()
@@ -164,6 +167,7 @@ function createSandbox() {
164167
sandbox.addEventListener('load', () => {
165168
proxy.handle_links()
166169
stopUpdateWatcher = watchEffect(updatePreview)
170+
switchPreviewTheme()
167171
})
168172
}
169173

0 commit comments

Comments
 (0)