go-app: Update of wasm binary doesn't trigger update of cached app

So here is very simple scenario

There is a message in main function

fmt.Println("Launching wasm app")

it’s compiled and loaded, message appears in console.

Now change it to

fmt.Println("Launching wasm app 1")

Put cursor in address bar, press enter - nothing happens. Then press Ctrl-F5 (force reload), new message appears. Then try pressing Ctrl-R (regular reload), old message will come back, same if you put cursor in address bar and press enter - old message is there.

Tested in latest Firefox and Chrome on desktop.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (17 by maintainers)

Most upvoted comments

Sorry to dominate this issue with tangential topics, but I’m enjoying the conversation and selfishly continuing - feel free to minimize. 😃

@oderwat For context, the UI I’m building is a CI/CD build view, which is powered by OpenTelemetry traces + logs under the hood. Here’s a screenshot of the current React version. Up until now we’ve been sending all the OpenTelemetry data to the client to process and render. It’s “fine” for small/medium traces, but it’s highly variable: our full integration test suite generates ~200MB of just trace data, not even including logs. 😱

We’ve been able to kick the can down the road on this in React, since the only real bottleneck is the network. It’s still not OK, since not everyone has fast internet, but the loose coupling has let us quickly iterate on the UI. With WebAssembly we’re forced to solve this sooner as the constraints are harsher, but it’s for the best.

So, fully agreed that processing 200MB client-side is not OK. That’s already fixed in my Go-App version, essentially as you described, via server-side processing and sending only visible data via WebSockets as the user expands/collapses spans in the UI. Now memory usage is under control, and the app is snappy. I only brought it up as an example where the caching behavior can be cumbersome while you iterate towards that. It’s a very complicated optimization to implement (with more work still to be done), so I was focusing on other risk factors first.

Before commenting on the slowness: There is a hard limit on how much memory (not storage) you can allocate in iOS which seems to be about 200 MB. After that your app gets killed. The GC of Go, will happily allocate even more than you expect if you do not tame it. I actually do not know the memory limit in android, but it is higher, and we need to support iOS, so I do not care. 😃

Haha, yep ran into this already; my app was OOMing in Firefox, but fine in Chrome, but sometimes fine in Firefox depending on… well, I don’t even know. It seems pretty easy for allocations to outpace the GC when you’re hurling 200MB+ of data around.

Out of the context I suppose that this happens in the frontend. There is (and most likely never will) be a way to update code and not restart your app in the frontend. This is asking that one can update lets say Microsoft Word while you are editing a Letter inside of it. Your app in the frontend is a program and this program is fully encapsulated in the app.wasm file compiled from the fronted part of the Go code. This needs to be compiled and then downloaded by the app, after that happened, the browser is reloaded. Even if you would create a new WASM module and run this and stop the old one. The application code would start all over.

But after you update the app and restart the server, listen to the update and automatically trigger a reload (which is what you should and need to do). It will be the “first page load”. Every single reload is always “the first page load”, even if you have multiple URLs and put them into the address bar, each of them will be “first page load”. The app does not “load” anything at all when switching URLs or changing state.

Understood, sorry for the distraction here, it was a poorly made point while rushing out the door. I don’t expect a magical live updating experience. I just don’t want it to cache the app so aggressively during development so I can do simple things like open links in new tabs without having to hard-refresh or restart the server all the time (assuming something is rebuilding app.wasm on code change). If that means throwing out the PWA aspect during development, so be it!

You could check out other alternatives. Go-App is not really a “Go Web Framework” it is a Go code based PWA framework (see below).

I think Go-App is a more appropriate choice for my use case than the other options; it’s much closer to a full blown interactive app than a vanilla CRUD website. I don’t really care about offline mode, so it may seem like an odd choice if that’s the initial purpose for Go-App existing, but there’s a lot more to Go-App than that. Specifically, I like Go-App’s rendering + components model, and the fact that I can try all sorts of optimizations, which will be important for users sifting through large traces.

I’ve used HTMX + Templ in the past for Daggerverse and so far I like Go-App more; it’s a much easier transition from React, especially for interactive apps.

  • Maybe Go-App could have a mode that does not use any caching? I mean it just loads the WASM and does not install and use the service worker at all. I think that could actually make it possible to test and develop components more quickly and have it reloading. I have to say that I did not think that through and only have a vague idea that this is possible.

Happy to try PRing this sometime!

I dealt with this with a wrapper which periodically checks the modification / hash (and a sync.RWMutex, as you say, @inliquid)

https://gist.github.com/tiedotguy/b8a29519c4690b45f89c003a37e36402

It’s a bit more complicated in reality 'cause I’ve got some fsnotify junk in there, but I don’t like that code, and it doesn’t contribute anything, so I’ve stripped it.