]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(sfc-playground): teardown preview update watcher
authorEvan You <yyx990803@gmail.com>
Wed, 31 Mar 2021 16:22:08 +0000 (12:22 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 31 Mar 2021 16:22:25 +0000 (12:22 -0400)
packages/sfc-playground/src/output/Preview.vue

index 230025a5f4d0064e66a198d919439b115c28894e..637b618eb9fcc22aec5d15008d1e9a92a1018687 100644 (file)
@@ -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>