fix: preserve context across SSE reconnects on tab visibility change
Datastar aborts SSE on visibilitychange (tab hidden) and reconnects when visible. The previous cleanup-on-disconnect destroyed the context before the client could reconnect. Now SSE disconnect does a soft teardown (mark disconnected, keep context alive) and reconnect drains stale patches before resuming. The reaper uses disconnect time instead of creation time so recently-disconnected contexts aren't prematurely reaped.
This commit is contained in:
@@ -39,8 +39,9 @@ type Context struct {
|
||||
subscriptions []Subscription
|
||||
subsMu sync.Mutex
|
||||
disposeOnce sync.Once
|
||||
createdAt time.Time
|
||||
sseConnected atomic.Bool
|
||||
createdAt time.Time
|
||||
sseConnected atomic.Bool
|
||||
sseDisconnectedAt atomic.Pointer[time.Time]
|
||||
}
|
||||
|
||||
// View defines the UI rendered by this context.
|
||||
|
||||
Reference in New Issue
Block a user