go-app
go-app copied to clipboard
404 NotFound displayed During Update
When calling app.Reload() there is a flash of the 404 before displaying the root component.
The same was happening when I use the following javascript to trigger the reload (before you implemented app.Reload() ):
navigator.serviceWorker.getRegistration().then(function(reg) {
if (reg) {
reg.unregister().then(function() { window.location.reload(); });
} else {
window.location.reload();
}
});
On the surface this can be fixed with the following diff. The strings.TrimPrefix results in an empty string, which of course is not registered in routes. It makes no difference if the app is currently on a routed uri besides the root. Upon refresh there is this initial routing to the root that is converted to "" by the strings.TrimPrefix call.
diff --git a/pkg/app/app_wasm.go b/pkg/app/app_wasm.go
index f9f9e70..9282e84 100644
--- a/pkg/app/app_wasm.go
+++ b/pkg/app/app_wasm.go
@@ -199,7 +199,11 @@ func navigate(u *url.URL, updateHistory bool) error {
path = "/" + path
}
- root, ok := routes.ui(strings.TrimPrefix(u.Path, rootPrefix))
+ uriPath := strings.TrimPrefix(u.Path, rootPrefix)
+ if uriPath == "" {
+ uriPath = "/"
+ }
+ root, ok := routes.ui(uriPath)
if !ok {
root = NotFound
}
related to https://github.com/maxence-charriere/go-app/issues/440
I don't arrive to reproduce this. Are you sure it is not the spinning loading logo?
I don't normally record my screen, but captured this with quicktime. It happens before the current version of the app is torn down and the new version launched. https://user-images.githubusercontent.com/1198324/105847983-fc2c4600-5fa3-11eb-8889-d8476f8b6438.mov
What version of the package are you using? Can i see your routes ? (Nice ui btw) Is it happening to all the url paths ?
I've seen this in go-app 7.x, was ignoring it while focusing on other things. Then when you brought in the OnAppUpdate I continue to see it in 7.2.0.
Here's the routes as registered in main
app.Route("/", module.CreateListingComponent(svc, model))
app.RouteWithRegexp("/add.*", module.CreateFeedbackComponent(svc, model))
app.Route("/about", module.CreateAboutComponent(model, svc))
app.Route("/tellus", module.CreateTellUsComponent(model, svc))
app.Route("/terms", module.CreateTermsComponent(model, svc))
app.Route("/pairings", module.CreatePairings(svc, model, svc))
app.Route("/login", module.CreateAutoLoginComponent(model))
app.Route("/team", module.CreateTeamComponent(model, svc))
app.Route("/questions", module.CreateQuestionsComponent(model, svc))
and as seen in a quick debugging print go-app app_wasm when I see it route to NotFound:
fmt.Printf("route (%s) not found amoung the following\n", uriPath)
for k := range routes.routes {
fmt.Println("route: ", k)
}
outputs:
route () not found among the following
route: /questions
route: /
route: /about
route: /tellus
route: /terms
route: /pairings
route: /login
And thanks on the UI. I got some help from a friend and built it using the no-longer-supported but still awesome https://getmdl.io/components/index.html