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
This commit is contained in:
Haoqing Wang
2026-04-11 16:50:39 +08:00
committed by GitHub
parent 30f8b125a6
commit f04a6fa226
+5 -3
View File
@@ -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' })