webxdc / webxdc-dev

A development server for webxdc apps
The Unlicense
18 stars 4 forks source link

Flash of contents #16

Open faassen opened 2 years ago

faassen commented 2 years ago

When a webxdc instance is opened on a port, there is sometimes a flash of contents. This happens to clear the local state (localstorage, etc) of the previous instance so we start with a fresh slate, and then the application is reloaded. After this, the setUpdateListener is registered for serial 0 and the state is loaded anew.

How to avoid this flash of content? The trouble is that we don't know whether clear is going to come in. A normal reload shouldn't wipe local state, only the initial opening does.

I considered turning off the UI (by setting document.style.display = 'none') in the window.load event but:

I considered loading a custom index.html initially when you open a tab, and then clearing contents if a clear event comes from the server, and buffering any other updates somehow, and then reloading to the real index.html and piping in all the buffered updates. But this seems very tricky to get right.

Perhaps the simplest approach would be some kind of setTimeout, but again the reload makes things difficult...