Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove infinite loop in replaceRoot #796

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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