8.0.0.3 Start in Desktop Browser PWA issue

When I updated to 8.0.0.3, I noticed that the tabs are no longer duplicated. Great, nice, very helpful. See post How to "start in desktop browser" without a new tab everytime for background.

But, I’ve found, as posted here Start in Desktop Browser starts program twice - windows with chrome, the pwa is invoking a reload unnecessarily in certain circumstances…

I found, similar to the problem in Modifying PWA.js code with ChangeForm, that if you close chrome between each invocation via desktop browser, that everything works fine. But if you leave the chrome open, press the deploy in AS without making any changes from the last time and leaving AS open from the last time, that the pwa now thinks it needs to reload. But there were no changes, so no reload is necessary.

Is AS changing some file cache indicator for one of the project files from deploy to deploy in desktop browser?

Not that we know of. I wouldn’t even know how to do this. The whole area of PWA refresh is not well documented.

I can live with the behavior. It’s not going to be seen by a user, so it doesn’t matter. It’s just an annoyance. But how often do you NOT make a change and restart the program :slight_smile: You’re always making changes, so this is a non issue, other than something odd is happening under the covers with PWA. I think it is related to the issue in Modifying PWA.js code (post 7). And it may be a chromium issue.

I finally figured out what is going on. There are some problems with PWA, but I’m not sure there are solutions or a need for one. But it sure is an annoyance. I just made a major change in a project’s file structure and another related issue came up and I realized what was going on with this issue as well.

PWA uses cache to start the program, and then checks with the server later to see if there is any file that has changed verses what is in the cache. If one or more files changed, then these files are downloaded, and the program restarts with the fresh copy (assuming you haven’t captured the onPWAreload() event).

But, when you start in desktop browser (SIDB), it’s a little different. This scenario is quite annoying: First, start the app with SIDB, leave AppStudio (AS) and chrome open, and SIDB the project again. The index.html file appears as a new file to chrome, even though it hasn’t been changed, and this should trigger the PWA to reload, even though there were not any changes. Not sure this is a problem, but …

Starting the SIDB the second time causes AS to send a fresh copy of index.html to chrome with a navigate parameter, so the index.html file is loaded immediately. The rest of the files would normally be loaded by index.html, but this is a pwa, so that is delayed. (Edit: It is not delayed, the reload is never fired. I’m not sure why it doesn’t fire consistently.) So now you are running with a fresh copy of the index.html with stale copies of the rest of the app. So if the change you just made was in one of those stale copies, it makes it appear your change didn’t work. You start checking the obvious, but not the source - only to find you need to reload again.

In my case, I had consolidated 6 .js files into one .js file. The other five were missing and those variable definitions caused errors. This caused a full app halt and the realization of what was happening.

This has bothered me as I was not sure why this was happening and hoping it would not/could not happen in the field. Now I know that it won’t, it is just the nature of SIDB. Hope this info helps someone else whose been scratching their heads. Maybe a resolution to this can be addressed?

A workaround might be to deploy to a local folder.

The easiest way is to “remember” to press Hard Reload (right click on reload button only available in inspector mode) and that forces the reload. The Hard Reload and Empty Cache also works. I’m getting better at remembering. Or remember to close the Chrome window before SIDB also works.

Running my app from local folder causes Uncaught DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules, as I’m messing with dark mode. I probably could track that down and make a workaround too, but I think “remembering” is the direction I’ll take.

The important thing here is: This does not affect production server distributions of the app.

I added the following to my Main() and so far it seems to be doing the job of forcing the reload of pages when using SIDB.

  var HostDomain = window.location.host.toLowerCase();
  if (HostDomain.substr(0, 4) == 'www.') {
    HostDomain = HostDomain.substr(4);
    };
  
  switch (HostDomain) {
    case "127.0.0.1:62000":
      if (localStorage.getItem('LocalHost') == null) {
        localStorage.setItem('LocalHost', 'true');
        location.reload(true);   // perform hard reload
        } else {
        localStorage.removeItem('LocalHost');
        };
      ...

UPDATE: I found that the reload is NOT immediate. In my case, the main() managed to trigger two ajax server calls before the reload. I added a return; after the reload statement to ensure the main() exited immediately. Do remember, AppStudio also has a few setTimeout functions that can also execute after the main() returns and before the reload occurs, but should not cause any issues.