From e37da6f1bda88c10435f142f5dc94c908cf36ac2 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Mon, 17 Jul 2023 19:29:28 +0200 Subject: [PATCH] fix: yjs duplicated import issue Signed-off-by: Luka Trovic --- src/components/Editor.singleton.js | 24 ++++++++++++++++++++++++ src/components/ViewerComponent.vue | 3 ++- src/views/RichWorkspace.vue | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/components/Editor.singleton.js diff --git a/src/components/Editor.singleton.js b/src/components/Editor.singleton.js new file mode 100644 index 00000000000..b8f89a24ffc --- /dev/null +++ b/src/components/Editor.singleton.js @@ -0,0 +1,24 @@ +/** + * Get instance of Editor component + * @return {Promise<*>} + */ +export default async function getEditorInstance() { + if (!window.EditorInstance) { + if (window.EditorInstanceImporting) { + return await new Promise((resolve) => { + const intervalId = setInterval(() => { + if (!window.EditorInstance) { + return + } + resolve(window.EditorInstance) + clearInterval(intervalId) + }, 200) + }) + } else { + window.EditorInstanceImporting = true + } + const Editor = await import(/* webpackChunkName: "editor" */'./Editor.vue') + window.EditorInstance = Editor.default + } + return window.EditorInstance +} diff --git a/src/components/ViewerComponent.vue b/src/components/ViewerComponent.vue index 6ddb359ae4f..43fa7530fba 100644 --- a/src/components/ViewerComponent.vue +++ b/src/components/ViewerComponent.vue @@ -32,11 +32,12 @@