@@ -154,7 +154,9 @@ func (v *V) Page(route string, initContextFn func(c *Context)) {
154154 }
155155 v .mux .HandleFunc ("GET " + route , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
156156 v .logDebug (nil , "GET %s" , r .URL .String ())
157- if strings .Contains (r .URL .Path , "favicon" ) {
157+ if strings .Contains (r .URL .Path , "favicon" ) ||
158+ strings .Contains (r .URL .Path , ".well-known" ) ||
159+ strings .Contains (r .URL .Path , "js.map" ) {
158160 return
159161 }
160162 id := fmt .Sprintf ("%s_/%s" , route , genRandID ())
@@ -235,9 +237,6 @@ func (v *V) HandleFunc(pattern string, f http.HandlerFunc) {
235237
236238// Start starts the Via HTTP server on the given address.
237239func (v * V ) Start () {
238- if v .cfg .DevMode {
239- v .devModeRestore ()
240- }
241240 v .logInfo (nil , "via started at [%s]" , v .cfg .ServerAddress )
242241 log .Fatalf ("[fatal] %v" , http .ListenAndServe (v .cfg .ServerAddress , v .mux ))
243242}
@@ -307,7 +306,7 @@ func (v *V) devModeRemovePersisted(c *Context) {
307306 v .logDebug (c , "devmode removed persisted ctx from file" )
308307}
309308
310- func (v * V ) devModeRestore () {
309+ func (v * V ) devModeRestore (cID string ) {
311310 p := filepath .Join (".via" , "devmode" , "ctx.json" )
312311 file , err := os .Open (p )
313312 if err != nil {
@@ -324,17 +323,18 @@ func (v *V) devModeRestore() {
324323 return
325324 }
326325 for ctxID , pageRoute := range ctxRegMap {
327- pageInitFn , ok := v .devModePageInitFnMap [pageRoute ]
328- if ! ok {
329- v .logWarn (nil , "devmode could not restore ctx from file: page init fn for route '%s' not found" , pageRoute )
330- continue
326+ if ctxID == cID {
327+ pageInitFn , ok := v .devModePageInitFnMap [pageRoute ]
328+ if ! ok {
329+ v .logWarn (nil , "devmode could not restore ctx from file: page init fn for route '%s' not found" , pageRoute )
330+ continue
331+ }
332+ c := newContext (ctxID , pageRoute , v )
333+ pageInitFn (c )
334+ v .registerCtx (c )
335+ v .logDebug (c , "devmode restored ctx" )
331336 }
332-
333- c := newContext (ctxID , pageRoute , v )
334- pageInitFn (c )
335- v .registerCtx (c )
336337 }
337- v .logDebug (nil , "devmode restored ctx registry" )
338338}
339339
340340type patchType int
@@ -375,6 +375,12 @@ func New() *V {
375375 var sigs map [string ]any
376376 _ = datastar .ReadSignals (r , & sigs )
377377 cID , _ := sigs ["via-ctx" ].(string )
378+
379+ if v .cfg .DevMode {
380+ if _ , err := v .getCtx (cID ); err != nil {
381+ v .devModeRestore (cID )
382+ }
383+ }
378384 c , err := v .getCtx (cID )
379385 if err != nil {
380386 v .logErr (nil , "sse stream failed to start: %v" , err )
@@ -385,9 +391,6 @@ func New() *V {
385391
386392 v .logDebug (c , "SSE connection established" )
387393
388- c .patchChan = make (chan patch , 1000 )
389- defer close (c .patchChan )
390-
391394 go func () {
392395 c .Sync ()
393396 }()
0 commit comments