fix: always signal connected state on first successful connect
markConnected skipped onReconnect when hasConnected was false and there was no prior disconnect. Consumer state (isConnected) starts at false and stayed false — the send button threw "Connection lost" until the HTTP health check in initializeApp happened to race a setState through. Now onReconnect fires on every successful connect; hasConnected is no longer needed and gets removed.
This commit is contained in:
@@ -146,7 +146,6 @@ type DirectoryQueue = {
|
||||
export function createEventPipeline(input: EventPipelineInput) {
|
||||
const { sdk, onEvent, onReconnect, onDisconnect, routeDirectory, transport = "auto" } = input
|
||||
const abort = new AbortController()
|
||||
let hasConnected = false
|
||||
let disconnected = false
|
||||
let lastEventId: string | undefined
|
||||
let wsFallbackUntil = 0
|
||||
@@ -245,19 +244,13 @@ export function createEventPipeline(input: EventPipelineInput) {
|
||||
let heartbeat: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
const markConnected = () => {
|
||||
const wasDisconnected = disconnected
|
||||
disconnected = false
|
||||
if (hasConnected) {
|
||||
onReconnect?.()
|
||||
return
|
||||
}
|
||||
hasConnected = true
|
||||
// First successful connect, but an earlier attempt already fired onDisconnect
|
||||
// (e.g. sidecar was not ready at launch). Consumer state is stuck at
|
||||
// isConnected=false — fire onReconnect to unstick it.
|
||||
if (wasDisconnected) {
|
||||
onReconnect?.()
|
||||
}
|
||||
// Fire onReconnect on every successful connect — including the very
|
||||
// first one. Consumer state (isConnected) starts at false and needs
|
||||
// to be flipped positively; without this the send button throws
|
||||
// "Connection lost" until something else (HTTP health check) happens
|
||||
// to race a setState({isConnected: true}) through.
|
||||
onReconnect?.()
|
||||
}
|
||||
|
||||
const enqueueEvent = (directory: string, payload: Event) => {
|
||||
|
||||
Reference in New Issue
Block a user