Don't let a failing initial fetch block the socket/polling fallback
onMounted awaited the initial REST calls before setting up the socket and the 6s polling fallback, so any rejected request aborted the handler and left the badge stuck on "connecting". Set up the socket and fallback first, make the initial loads best-effort, and log [ws] connect/open/close for debugging.
This commit is contained in:
1 parent
7057a5999e
commit
cf54ff8b45
2 files changed
+19
-9
No files matched your search
@@ -48,6 +48,7 @@ export function openSocket({ onMessage, onOpen, onClose, onError }) {
|
||||
if (closed) return
|
||||
let opened = false
|
||||
let reported = false
|
||||
console.debug('[ws] connecting to', url)
|
||||
socket = new WebSocket(url)
|
||||
|
||||
// Report at most one failure per attempt (Safari often fires error *and*
|
||||
@@ -72,11 +73,13 @@ export function openSocket({ onMessage, onOpen, onClose, onError }) {
|
||||
opened = true
|
||||
clearTimeout(openTimeout)
|
||||
attempt = 0
|
||||
console.debug('[ws] open')
|
||||
onOpen?.()
|
||||
}
|
||||
socket.onmessage = (event) => onMessage?.(JSON.parse(event.data))
|
||||
socket.onclose = (event) => {
|
||||
clearTimeout(openTimeout)
|
||||
console.debug('[ws] close', event.code, event.reason)
|
||||
onClose?.()
|
||||
if (!opened) {
|
||||
// 1008 = policy violation (token rejected); 1006 = abnormal close.
|
||||
|
||||
Reference in new issue
Block a user