Skip to content

Commit 36c0fb9

Browse files
committed
fix(runtime): solve chan blocks; other small improvements
1 parent a71d6f0 commit 36c0fb9

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

context.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (c *Context) Signal(v any) *signal {
184184

185185
func (c *Context) injectSignals(sigs map[string]any) {
186186
if sigs == nil {
187-
c.app.logErr(c, "signal injection failed: nil signals in ctx")
187+
c.app.logErr(c, "signal injection failed: nil signals")
188188
return
189189
}
190190

@@ -320,7 +320,9 @@ func (c *Context) ExecScript(s string) {
320320
func (c *Context) stopAllRoutines() {
321321
select {
322322
case c.ctxDisposedChan <- struct{}{}:
323+
c.app.logDebug(c, "stopped all routines")
323324
default:
325+
c.app.logDebug(c, "did not stop all routines")
324326
}
325327

326328
}
@@ -337,6 +339,6 @@ func newContext(id string, route string, v *V) *Context {
337339
componentRegistry: make(map[string]*Context),
338340
actionRegistry: make(map[string]func()),
339341
signals: new(sync.Map),
340-
ctxDisposedChan: make(chan struct{}),
342+
ctxDisposedChan: make(chan struct{}, 1),
341343
}
342344
}

via.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (v *V) Page(route string, initContextFn func(c *Context)) {
153153
v.devModePageInitFnMap[route] = initContextFn
154154
}
155155
v.mux.HandleFunc("GET "+route, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
156-
v.logDebug(nil, "GET %s", route)
156+
v.logDebug(nil, "GET %s", r.URL.String())
157157
if strings.Contains(r.URL.Path, "favicon") {
158158
return
159159
}
@@ -389,11 +389,7 @@ func New() *V {
389389
defer close(c.patchChan)
390390

391391
go func() {
392-
if v.cfg.DevMode {
393-
c.Sync()
394-
} else {
395-
c.SyncSignals()
396-
}
392+
c.Sync()
397393
}()
398394

399395
for {
@@ -403,23 +399,23 @@ func New() *V {
403399
return
404400
case patch, ok := <-c.patchChan:
405401
if !ok {
406-
return
402+
continue
407403
}
408404
switch patch.typ {
409405
case patchTypeElements:
410406
if err := sse.PatchElements(patch.content); err != nil {
411407
v.logErr(c, "PatchElements failed: %v", err)
412-
return
408+
continue
413409
}
414410
case patchTypeSignals:
415411
if err := sse.PatchSignals([]byte(patch.content)); err != nil {
416412
v.logErr(c, "PatchSignals failed: %v", err)
417-
return
413+
continue
418414
}
419415
case patchTypeScript:
420416
if err := sse.ExecuteScript(patch.content, datastar.WithExecuteScriptAutoRemove(true)); err != nil {
421417
v.logErr(c, "ExecuteScript failed: %v", err)
422-
return
418+
continue
423419
}
424420
}
425421
}

0 commit comments

Comments
 (0)