Document and patch historical prefix claiming, and handle reconnect interval better

This commit is contained in:
Jack Kingsman
2026-02-09 20:25:21 -08:00
parent 9294ffe138
commit cf215c4ba5
6 changed files with 39 additions and 2 deletions
+8
View File
@@ -60,6 +60,10 @@ export function useWebSocket(options: UseWebSocketOptions) {
ws.onopen = () => {
console.log('WebSocket connected');
setConnected(true);
if (reconnectTimeoutRef.current) {
clearTimeout(reconnectTimeoutRef.current);
reconnectTimeoutRef.current = null;
}
};
ws.onclose = () => {
@@ -68,6 +72,9 @@ export function useWebSocket(options: UseWebSocketOptions) {
wsRef.current = null;
// Reconnect after 3 seconds
if (reconnectTimeoutRef.current) {
clearTimeout(reconnectTimeoutRef.current);
}
reconnectTimeoutRef.current = window.setTimeout(() => {
console.log('Attempting WebSocket reconnect...');
connect();
@@ -146,6 +153,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
clearInterval(pingInterval);
if (reconnectTimeoutRef.current) {
clearTimeout(reconnectTimeoutRef.current);
reconnectTimeoutRef.current = null;
}
if (wsRef.current) {
wsRef.current.close();