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