Skip to content

Commit 9d65ba9

Browse files
committed
fix: on unmounted is placed inside onmounted warning
1 parent e3e9a31 commit 9d65ba9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/runtime/components/NuxtCodeMirror.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ViewUpdate, EditorView } from '@codemirror/view'
33
import type { EditorState } from '@codemirror/state'
44
import { useNuxtCodeMirror } from '../composables/useNuxtCodeMirror'
55
import type { NuxtCodeMirrorProps, Statistics } from '../types/nuxt-codemirror'
6-
import { onMounted, ref, watch, nextTick, computed } from '#imports'
6+
import { onMounted, ref, watch, nextTick, computed, onBeforeUnmount } from '#imports'
77
88
const editor = ref<HTMLDivElement | null>(null)
99
const container = ref<HTMLDivElement | null>(null)
@@ -57,6 +57,13 @@ onMounted(async () => {
5757
// console.log('test: ', view.value)
5858
})
5959
60+
onBeforeUnmount(() => {
61+
if (view.value) {
62+
view.value?.destroy()
63+
view.value = undefined
64+
}
65+
})
66+
6067
watch(() => modelValue, (newValue) => {
6168
if (typeof newValue !== 'string') {
6269
console.error(`value must be typeof string but got ${typeof newValue}`)

src/runtime/composables/useNuxtCodeMirror.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EditorView, type ViewUpdate } from '@codemirror/view'
33
import { getDefaultExtensions } from '../getDefaultExtensions'
44
import { type UseCodeMirrorProps } from '../types/nuxt-codemirror'
55
import { getStatistics } from '../utils/utils'
6-
import { onUnmounted, watch, watchEffect } from '#imports'
6+
import { onBeforeUnmount, watch, watchEffect } from '#imports'
77

88
const External = Annotation.define<boolean>()
99

@@ -167,11 +167,4 @@ export function useNuxtCodeMirror(props: UseCodeMirrorProps) {
167167
},
168168
{ immediate: true },
169169
)
170-
171-
onUnmounted(() => {
172-
if (viewRef) {
173-
viewRef.value?.destroy()
174-
viewRef.value = undefined
175-
}
176-
})
177170
}

0 commit comments

Comments
 (0)