From b046b8784e3b8f29ca5576ddd6601171affd5b6c Mon Sep 17 00:00:00 2001 From: SeptemberHX Date: Sat, 13 Aug 2022 09:36:43 +0800 Subject: [PATCH] fix: issue #6719. Avoid reloading loaded plugins --- .../NoteBody/CodeMirror/utils/useExternalPlugins.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useExternalPlugins.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useExternalPlugins.ts index e2a5f6bf3b0..6be7791cbf2 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useExternalPlugins.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useExternalPlugins.ts @@ -7,6 +7,8 @@ import uuid from '@joplin/lib/uuid'; import { reg } from '@joplin/lib/registry'; +const loadedPluginIdSet = new Set(); + export default function useExternalPlugins(CodeMirror: any, plugins: PluginStates) { const [options, setOptions] = useState({}); @@ -17,6 +19,10 @@ export default function useExternalPlugins(CodeMirror: any, plugins: PluginState for (const contentScript of contentScripts) { try { + if (loadedPluginIdSet.has(contentScript.id)) { + continue; + } + const mod = contentScript.module; if (mod.codeMirrorResources) { @@ -64,6 +70,8 @@ export default function useExternalPlugins(CodeMirror: any, plugins: PluginState if (mod.plugin) { mod.plugin(CodeMirror); } + + loadedPluginIdSet.add(contentScript.id); } catch (error) { reg.logger().error(error.toString()); }