Always sync full state when SSE connects

Previously only called Sync() on SSE reconnect (detected via last-event-id
header). This caused issues when application code registered contexts for
updates before the SSE connection was established - patches sent to
patchChan could be dropped.

Now always call Sync() when SSE connects, ensuring clients receive the
full current state regardless of what happened before the connection
was established.

Fixes #2
This commit is contained in:
Ryan Hamamura
2026-01-14 19:02:44 -10:00
parent c77ccc0796
commit 73f4e4009b

10
via.go
View File

@@ -408,10 +408,6 @@ func New() *V {
} }
v.mux.HandleFunc("GET /_sse", func(w http.ResponseWriter, r *http.Request) { v.mux.HandleFunc("GET /_sse", func(w http.ResponseWriter, r *http.Request) {
isReconnect := false
if r.Header.Get("last-event-id") == "via" {
isReconnect = true
}
var sigs map[string]any var sigs map[string]any
_ = datastar.ReadSignals(r, &sigs) _ = datastar.ReadSignals(r, &sigs)
cID, _ := sigs["via-ctx"].(string) cID, _ := sigs["via-ctx"].(string)
@@ -436,11 +432,7 @@ func New() *V {
v.logDebug(c, "SSE connection established") v.logDebug(c, "SSE connection established")
go func() { go func() {
if isReconnect || v.cfg.DevMode { c.Sync()
c.Sync()
return
}
c.SyncSignals()
}() }()
for { for {