Skip to content

Commit 3df241f

Browse files
committed
refactor: add ref types
1 parent d786626 commit 3df241f

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/Message.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ref, watch } from 'vue'
33
import type { CompilerError } from 'vue/compiler-sfc'
44
55
const props = defineProps<{
6-
err?: string | Error
6+
err?: string | Error | false
77
warn?: string | Error
88
}>()
99

src/SplitPane.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function dragEnd() {
5454
5555
function changeViewSize() {
5656
const el = previewRef.value
57+
if (!el) return
5758
state.viewHeight = el.offsetHeight
5859
state.viewWidth = el.offsetWidth
5960
}

src/output/Preview.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const props = defineProps<{ show: boolean; ssr: boolean }>()
1919
const { store, clearConsole, theme, previewTheme, previewOptions } =
2020
inject(injectKeyProps)!
2121
22-
const container = ref()
23-
const runtimeError = ref()
24-
const runtimeWarning = ref()
22+
const container = ref<HTMLDivElement>()
23+
const runtimeError = ref<string>()
24+
const runtimeWarning = ref<string>()
2525
2626
let sandbox: HTMLIFrameElement
2727
let proxy: PreviewProxy
@@ -68,7 +68,7 @@ function createSandbox() {
6868
// clear prev sandbox
6969
proxy.destroy()
7070
stopUpdateWatcher && stopUpdateWatcher()
71-
container.value.removeChild(sandbox)
71+
container.value?.removeChild(sandbox)
7272
}
7373
7474
sandbox = document.createElement('iframe')
@@ -101,7 +101,7 @@ function createSandbox() {
101101
previewOptions.value?.placeholderHTML || '',
102102
)
103103
sandbox.srcdoc = sandboxSrc
104-
container.value.appendChild(sandbox)
104+
container.value?.appendChild(sandbox)
105105
106106
proxy = new PreviewProxy(sandbox, {
107107
on_fetch_progress: (progress: any) => {
@@ -169,8 +169,8 @@ async function updatePreview() {
169169
if (import.meta.env.PROD && clearConsole.value) {
170170
console.clear()
171171
}
172-
runtimeError.value = null
173-
runtimeWarning.value = null
172+
runtimeError.value = undefined
173+
runtimeWarning.value = undefined
174174
175175
let isSSR = props.ssr
176176
if (store.value.vueVersion) {
@@ -290,7 +290,7 @@ defineExpose({ reload, container })
290290
class="iframe-container"
291291
:class="{ [theme]: previewTheme }"
292292
/>
293-
<Message :err="runtimeError && (previewOptions?.showRuntimeError ?? true)" />
293+
<Message :err="(previewOptions?.showRuntimeError ?? true) && runtimeError" />
294294
<Message
295295
v-if="!runtimeError && (previewOptions?.showRuntimeWarning ?? true)"
296296
:warn="runtimeWarning"

src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ export type OutputModes = 'preview' | EditorMode
1717

1818
export const injectKeyProps: InjectionKey<ToRefs<Required<Props>>> =
1919
Symbol('props')
20-
export const injectKeyPreviewRef: InjectionKey<ComputedRef<HTMLElement>> =
21-
Symbol('preview-ref')
20+
export const injectKeyPreviewRef: InjectionKey<
21+
ComputedRef<HTMLDivElement | undefined>
22+
> = Symbol('preview-ref')

0 commit comments

Comments
 (0)