From f04a6fa226040081bce5a1d0dcbb6836f7206896 Mon Sep 17 00:00:00 2001 From: Haoqing Wang <78337154+hqhq1025@users.noreply.github.com> Date: Sat, 11 Apr 2026 16:50:39 +0800 Subject: [PATCH] fix(web): use explicit Manager+socket for terminal namespace connection (#433) The convenience `io()` function misparses the `/terminal` path component as part of the Engine.IO endpoint in some browser environments, producing requests to `/terminal/socket.io/` instead of `/socket.io/`. Using `new Manager(baseUrl)` + `manager.socket('/terminal')` separates the transport URL from the namespace unambiguously. Closes #251 --- web/src/hooks/useTerminalSocket.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/src/hooks/useTerminalSocket.ts b/web/src/hooks/useTerminalSocket.ts index 225ff64b..4789aeed 100644 --- a/web/src/hooks/useTerminalSocket.ts +++ b/web/src/hooks/useTerminalSocket.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect, useRef, useState } from 'react' -import { io, type Socket } from 'socket.io-client' +import { Manager, type Socket } from 'socket.io-client' type TerminalConnectionState = | { status: 'idle' } @@ -116,8 +116,7 @@ export function useTerminalSocket(options: UseTerminalSocketOptions): { return } - const socket = io(`${baseUrlRef.current}/terminal`, { - auth: { token }, + const manager = new Manager(baseUrlRef.current, { path: '/socket.io/', reconnection: true, reconnectionAttempts: Infinity, @@ -126,6 +125,9 @@ export function useTerminalSocket(options: UseTerminalSocketOptions): { transports: ['polling', 'websocket'], autoConnect: false }) + const socket = manager.socket('/terminal', { + auth: { token } + }) socketRef.current = socket setState({ status: 'connecting' })