From 9e30e5915fb6fe823cec1a4e9221ddc4d2f132b1 Mon Sep 17 00:00:00 2001 From: Vantz Stockwell Date: Sat, 14 Mar 2026 01:56:59 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20SFTP=20sidebar=20empty=20on=20load=20?= =?UTF-8?q?=E2=80=94=20list=20sent=20before=20WebSocket=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list('/') call fired immediately after connect(), but the WebSocket was still in CONNECTING state so send() silently dropped the message. Now buffers the initial list request and sends it in the onopen callback. Co-Authored-By: Claude Opus 4.6 --- frontend/composables/useSftp.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/composables/useSftp.ts b/frontend/composables/useSftp.ts index 0d2f038..8597d1f 100644 --- a/frontend/composables/useSftp.ts +++ b/frontend/composables/useSftp.ts @@ -9,10 +9,19 @@ export function useSftp(sessionId: Ref) { const fileContent = ref<{ path: string; content: string } | null>(null) const transfers = ref([]) + let pendingList: string | null = null + function connect() { const wsUrl = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/api/ws/sftp?token=${auth.token}` ws = new WebSocket(wsUrl) + ws.onopen = () => { + if (pendingList !== null) { + send({ type: 'list', path: pendingList }) + pendingList = null + } + } + ws.onmessage = (event) => { const msg = JSON.parse(event.data) switch (msg.type) { @@ -48,7 +57,13 @@ export function useSftp(sessionId: Ref) { } } - function list(path: string) { send({ type: 'list', path }) } + function list(path: string) { + if (ws && ws.readyState === WebSocket.OPEN) { + send({ type: 'list', path }) + } else { + pendingList = path + } + } function readFile(path: string) { send({ type: 'read', path }) } function writeFile(path: string, data: string) { send({ type: 'write', path, data }) } function mkdir(path: string) { send({ type: 'mkdir', path }) }