浏览代码

chore(sfc-playground): teardown preview update watcher

Evan You 5 年之前
父节点
当前提交
7bc5fd9a04
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      packages/sfc-playground/src/output/Preview.vue

+ 4 - 1
packages/sfc-playground/src/output/Preview.vue

@@ -12,6 +12,7 @@
 <script setup lang="ts">
 import Message from '../Message.vue'
 import { ref, onMounted, onUnmounted, watchEffect } from 'vue'
+import type { WatchStopHandle } from 'vue'
 import srcdoc from './srcdoc.html?raw'
 import { PreviewProxy } from './PreviewProxy'
 import { MAIN_FILE, SANDBOX_VUE_URL } from '../sfcCompiler'
@@ -22,6 +23,7 @@ const runtimeError = ref()
 const runtimeWarning = ref()
 
 let proxy: PreviewProxy
+let updateHandle: WatchStopHandle
 
 async function updatePreview() {
   runtimeError.value = null
@@ -93,12 +95,13 @@ onMounted(() => {
 
   iframe.value.addEventListener('load', () => {
     proxy.handle_links()
-    watchEffect(updatePreview)
+    updateHandle = watchEffect(updatePreview)
   })
 })
 
 onUnmounted(() => {
   proxy.destroy()
+  updateHandle && updateHandle()
 })
 </script>