diff --git a/src/lib/components/editor/editor.svelte b/src/lib/components/editor/editor.svelte index fba5e70c..3b562c27 100644 --- a/src/lib/components/editor/editor.svelte +++ b/src/lib/components/editor/editor.svelte @@ -35,12 +35,22 @@ } const dispatch = createEventDispatcher(); - + const loadMonaco = async () => { + let i = 0; + while (i++ < 10) { + try { + //@ts-ignore : This is a hack to handle a svelte-kit error when importing monaco. + Monaco = monaco; + return; + } catch { + await new Promise((r) => setTimeout(r, 500)); + } + } + alert('Loading Monaco Editor failed. Please try refreshing the page.'); + }; onMount(async () => { - //@ts-ignore : This is a hack to handle a svelte-kit error when importing monaco. - Monaco = monaco; + await loadMonaco(); // Fix https://github.com/mermaid-js/mermaid-live-editor/issues/175 initEditor(Monaco); - editor = Monaco.editor.create(divEl, editorOptions); editor.onDidChangeModelContent(() => { text = editor.getValue();