From 4cad2dd8fafd63022f2cd9385b64c71d8bfa4f4c Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Mon, 20 May 2024 17:24:03 +0100 Subject: [PATCH] fix: gui tests --- app/gui2/src/stores/project/index.ts | 20 ++++++++++++++----- .../lib/dashboard/src/layouts/Editor.tsx | 14 ++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/gui2/src/stores/project/index.ts b/app/gui2/src/stores/project/index.ts index 59d2a5f6cf45..90b8e0dd2a2d 100644 --- a/app/gui2/src/stores/project/index.ts +++ b/app/gui2/src/stores/project/index.ts @@ -43,16 +43,27 @@ import * as Y from 'yjs' interface LsUrls { rpcUrl: string dataUrl: string - ydocUrl: string + ydocUrl: URL } function resolveLsUrl(config: GuiConfig): LsUrls { const engine = config.engine if (engine == null) throw new Error('Missing engine configuration') - if (engine.rpcUrl != null && engine.dataUrl != null && engine.ydocUrl != null) { + if (engine.rpcUrl != null && engine.dataUrl != null) { const dataUrl = engine.dataUrl const rpcUrl = engine.rpcUrl - const ydocUrl = engine.ydocUrl + + let ydocUrl: URL; + if (engine.ydocUrl == '') { + ydocUrl = new URL(location.origin) + ydocUrl.protocol = location.protocol.replace(/^http/, 'ws') + } else if (URL.canParse(engine.ydocUrl)) { + ydocUrl = new URL(engine.ydocUrl) + } else { + ydocUrl = new URL(rpcUrl) + ydocUrl.port = '1234' + } + ydocUrl.pathname = '/project' return { rpcUrl, @@ -136,11 +147,10 @@ export const useProjectStore = defineStore('project', () => { return tryQualifiedName(`${fullName.value}.${withDotSeparators}`) }) - const ydocUrl = new URL(lsUrls.ydocUrl) let yDocsProvider: ReturnType | undefined watchEffect((onCleanup) => { yDocsProvider = attachProvider( - ydocUrl.href, + lsUrls.ydocUrl.href, 'index', { ls: lsUrls.rpcUrl }, doc, diff --git a/app/ide-desktop/lib/dashboard/src/layouts/Editor.tsx b/app/ide-desktop/lib/dashboard/src/layouts/Editor.tsx index 6597036c5a34..85360e9ab6d7 100644 --- a/app/ide-desktop/lib/dashboard/src/layouts/Editor.tsx +++ b/app/ide-desktop/lib/dashboard/src/layouts/Editor.tsx @@ -83,17 +83,7 @@ export default function Editor(props: EditorProps) { } else if (binaryAddress == null) { toastAndLog('noBinaryEndpointError') } else { - let ydocAddress: URL - if (ydocUrl == null) { - ydocAddress = new URL(location.origin) - ydocAddress.protocol = location.protocol.replace(/^http/, 'ws') - } else if (URL.canParse(ydocUrl)) { - ydocAddress = new URL(ydocUrl) - } else { - ydocAddress = new URL(jsonAddress) - ydocAddress.port = '1234' - } - ydocAddress.pathname = '/project' + const ydocAddress = ydocUrl ?? '' let assetsRoot: string switch (backendType) { case backendModule.BackendType.remote: { @@ -115,7 +105,7 @@ export default function Editor(props: EditorProps) { const engineConfig = { rpcUrl: jsonAddress, dataUrl: binaryAddress, - ydocUrl: ydocAddress.toString(), + ydocUrl: ydocAddress, } const originalUrl = window.location.href if (backendType === backendModule.BackendType.remote) {