wq/wq.app

index.html is rendered using context only once

tomaszn opened this issue · 5 comments

I customized the start page for users. However, after logging into another account, the index.html page is not refreshed.

Yes, the index page has a few quirks due to how it is rendered. There are two general things to watch out for:

  1. Make sure that wq/app.js is aware of the index page
  2. If you are using the application cache, make sure you handle the initial render of the index page (which usually happens on the server) as a special case.

The symptoms are a little different in each case. For (1), if wq/app.js is not aware of the index (or any page) page, it will simply reuse the page as rendered by the server. So, if you start at the index page, log in, then go back to the index page without refreshing the application, the original index page will be preserved. You can get around this by ensuring wq/app.js re-renders the index page every time you navigate to it. The simple way to do this is to add the index to your rest.py registration, which will then add it to the configuration object.

rest.router.add_page('index', {'url': ''})

Case (2) is more tricky and only applies if you are using the application cache (with <html manifest=myproject.appcache>). In that case, when the index page is rendered by the server, it gets cached with whatever state the user had when they first accessed the application. When they log in and navigate back to the home screen, wq/app.js will redraw the screen (assuming case 1 is handled). But, if they refresh the index page, (or re-open the application after closing it) it will use the cached server-rendered version which may be incorrect.

To handle this second case, one option is to hook into the login/logout events to show or hide parts of the interface:

// myapp/main.js
$('body').on('login', function() {
    $('.show-when-logged-in').show();
    $('.show-when-logged-out').hide();
});

app.init(config).then(function() {
// ...

Another option is to force a redraw of the home screen whenever the application loads for the first time:

// myapp/main.js
app.init(config).then(function() {
    app.jqmInit();
    if ($.mobile.activePage.data('url') == '/') {
        app.nav(''); // or app.replaceState('') if using wq.app master
    }
}

I have a similar Issue:
The rendered index.html is not updated after I made changes to the template, even though I run deploy.sh 0.0.2 to update the templates.
This only happens when run via wsgi (I running it in a docker container). on the development server everything works as it should (but it's useless to me since I need it to work in production)
The funny thing is that the source obtained from the GET request on / is the updated one, but the page rendered is the older v. 0.0.1. I initially thought it might be a cache issue, but it perssists even after clearing the cache, and even on different browsers. I have rulled out caching of the docker image, but it continues even after I deleted all images and rebuild the containers from scratch.

I have also tried deleting htdocs and letting the deploy.sh script rebuild it. Nothing seems to work.

Any suggestions?

@fccoelho : Try removing it from generated htdocs/

@tomaszn what do you mean by "it" ?What exactly should I remove?

htdocs/index.html -- let's debug this in #118