Skip to content

Commit 4e2dd3a

Browse files
authored
fix: react and vue destroy when using crepe (#1679)
1 parent 9c1e777 commit 4e2dd3a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: packages/integrations/react/src/use-get-editor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function useGetEditor() {
3939
.catch(console.error)
4040

4141
return () => {
42-
editorRef.current?.destroy()
42+
editor.destroy()
4343
}
4444
}, [dom, editorRef, getEditor, setLoading])
4545

Diff for: packages/integrations/vue/src/use-get-editor.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { inject, onMounted, onUnmounted } from 'vue'
1+
import { inject, onMounted, onUnmounted, ref } from 'vue'
22

33
import type { EditorInfoCtx } from './types'
44
import { editorInfoCtxKey } from './consts'
5+
import type { Crepe } from '@milkdown/crepe'
6+
import type { Editor } from '@milkdown/kit/core'
57

68
export function useGetEditor() {
79
const {
@@ -10,6 +12,7 @@ export function useGetEditor() {
1012
editor: editorRef,
1113
editorFactory: getEditor,
1214
} = inject(editorInfoCtxKey, {} as EditorInfoCtx)
15+
const currentEditorRef = ref<Editor | Crepe>()
1316

1417
onMounted(() => {
1518
if (!dom.value) return
@@ -18,6 +21,7 @@ export function useGetEditor() {
1821
if (!editor) return
1922

2023
loading.value = true
24+
currentEditorRef.value = editor
2125
editor
2226
.create()
2327
.then((editor) => {
@@ -29,7 +33,7 @@ export function useGetEditor() {
2933
.catch(console.error)
3034
})
3135
onUnmounted(() => {
32-
editorRef.value?.destroy()
36+
currentEditorRef.value?.destroy()
3337
})
3438

3539
return dom

0 commit comments

Comments
 (0)