From 2dabb0f894399992305cdc7258c0d4375c49a254 Mon Sep 17 00:00:00 2001 From: LIlGG <1103069291@qq.com> Date: Wed, 1 Nov 2023 11:34:07 +0800 Subject: [PATCH] fix: optimize editor performance and resolve freezing issues --- .../src/components/editor/DefaultEditor.vue | 349 +++++++++--------- .../use-editor-extension-points.ts | 14 +- 2 files changed, 186 insertions(+), 177 deletions(-) diff --git a/console/src/components/editor/DefaultEditor.vue b/console/src/components/editor/DefaultEditor.vue index 63235794cd..23aff4ab0e 100644 --- a/console/src/components/editor/DefaultEditor.vue +++ b/console/src/components/editor/DefaultEditor.vue @@ -86,6 +86,7 @@ import { OverlayScrollbarsComponent } from "overlayscrollbars-vue"; import { usePluginModuleStore } from "@/stores/plugin"; import type { PluginModule } from "@halo-dev/console-shared"; import { useDebounceFn } from "@vueuse/core"; +import { onBeforeUnmount } from "vue"; const { t } = useI18n(); @@ -355,6 +356,10 @@ onMounted(() => { }); }); +onBeforeUnmount(() => { + editor.value?.destroy(); +}); + // image drag and paste upload const { policies } = useFetchAttachmentPolicy(); @@ -491,203 +496,205 @@ const currentLocale = i18n.global.locale.value as diff --git a/console/src/composables/use-editor-extension-points.ts b/console/src/composables/use-editor-extension-points.ts index 0dbbff05de..a1f3ab75a7 100644 --- a/console/src/composables/use-editor-extension-points.ts +++ b/console/src/composables/use-editor-extension-points.ts @@ -1,6 +1,6 @@ import { usePluginModuleStore } from "@/stores/plugin"; import type { EditorProvider, PluginModule } from "@halo-dev/console-shared"; -import { onMounted, ref, type Ref, defineAsyncComponent } from "vue"; +import { onMounted, ref, type Ref, defineAsyncComponent, markRaw } from "vue"; import { VLoading } from "@halo-dev/components"; import Logo from "@/assets/logo.png"; import { useI18n } from "vue-i18n"; @@ -18,11 +18,13 @@ export function useEditorExtensionPoints(): useEditorExtensionPointsReturn { { name: "default", displayName: t("core.plugin.extension_points.editor.providers.default"), - component: defineAsyncComponent({ - loader: () => import("@/components/editor/DefaultEditor.vue"), - loadingComponent: VLoading, - delay: 200, - }), + component: markRaw( + defineAsyncComponent({ + loader: () => import("@/components/editor/DefaultEditor.vue"), + loadingComponent: VLoading, + delay: 200, + }) + ), rawType: "HTML", logo: Logo, },