Skip to content

fix: remove infinite loop in replaceRoot#796

Open
TcMits wants to merge 1 commit intomaxence-charriere:masterfrom
TcMits:replaceRoot-infinite-loop
Open

fix: remove infinite loop in replaceRoot#796
TcMits wants to merge 1 commit intomaxence-charriere:masterfrom
TcMits:replaceRoot-infinite-loop

Conversation

@TcMits
Copy link
Contributor

@TcMits TcMits commented Dec 23, 2022

Hi @maxence-charriere

I ran into infinite loop when tried implementing something like this:

package main

import (
	"log"
	"net/http"

	"github.com/maxence-charriere/go-app/v9/pkg/app"
)

type compo struct {
	app.Compo
}

func (c *compo) Render() app.UI {
	return app.Div().Body(new(compoA))
}

type compoA struct {
	app.Compo
	isLoading bool
}

func (c *compoA) OnNav(app.Context) {
	c.isLoading = true
}

func (c *compoA) Render() app.UI {
	b := new(compoB)
	b.IsLoading = c.isLoading
	return b
}

type compoB struct {
	app.Compo
	IsLoading bool
}

func (c *compoB) Render() app.UI {
	return app.If(c.IsLoading, app.Div().Text("is loading")).Else(app.A().Text("is not loading"))
}

func main() {
	app.Route("/", new(compo))

	app.RunWhenOnBrowser()

	http.Handle("/", &app.Handler{
		Name:        "Hello",
		Description: "An Hello World! example",
	})

	if err := http.ListenAndServe(":8000", nil); err != nil {
		log.Fatal(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant