Skip to content

Commit 673e99b

Browse files
committed
fix: remove unneeded nextTick for syncing template ref
1 parent 9d65ba9 commit 673e99b

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

playground/app.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ const handleUpdate = (viewUpdate: ViewUpdate) => {
2626
2727
onMounted(() => {
2828
if (codemirror.value) {
29-
console.log('blaaaaa', codemirror.value.editor)
29+
console.log('Log editorRef', codemirror.value.editor)
30+
console.log('Log containerRef', codemirror.value.container)
3031
}
32+
33+
watchEffect(() => {
34+
if (codemirror.value) {
35+
console.log('Log StateRef', codemirror.value.state)
36+
console.log('Log viewRef', codemirror.value.view)
37+
}
38+
})
3139
})
3240
</script>
3341

src/runtime/components/NuxtCodeMirror.vue

Lines changed: 2 additions & 4 deletions
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, onBeforeUnmount } from '#imports'
6+
import { onMounted, ref, watch, computed, onBeforeUnmount } from '#imports'
77
88
const editor = ref<HTMLDivElement | null>(null)
99
const container = ref<HTMLDivElement | null>(null)
@@ -31,9 +31,7 @@ const emit = defineEmits<{
3131
(event: 'onUpdate' | 'onFocus' | 'onBlur', update: ViewUpdate): void
3232
}>()
3333
34-
onMounted(async () => {
35-
await nextTick()
36-
34+
onMounted(() => {
3735
useNuxtCodeMirror({
3836
...props,
3937
modelValue: modelValue.value,

src/runtime/composables/useNuxtCodeMirror.ts

Lines changed: 1 addition & 1 deletion
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 { onBeforeUnmount, watch, watchEffect } from '#imports'
6+
import { watch, watchEffect } from '#imports'
77

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

0 commit comments

Comments
 (0)