[SOLVED] Meteor.connected() not reactive?

Hello, I use Meteor.connected() to show a small loader before displaying the application content. It seems to work since I can see it flashing each time I reload the page but it doesn’t appear when I kill the server, is it normal ?

  • index.html
<div id="noLinkMessage">
    {{#if is_connected}}
        {{#if is_owner}}
            You don't have any link yet :(
        {{else}}
            This user doesn't have any link :(
        {{/if}}
    {{else}}
         DISCONNECTED
         <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
    {{/if}}
</div>
  • index.js
Template.index.helpers({
    username() {
        return FlowRouter.getParam('username');
    },
    is_connected() {
        return Meteor.status().connected;
    },
    is_owner() {
        if(Meteor.user())
            return (FlowRouter.getParam('username') === Meteor.user().username);
        else {
            return false;
        }
    },
    categories() {
        let cats = Categories.find(
            {owner: FlowRouter.getParam('username')},
            {sort: {createdAt: -1}}
        );
        return cats.count() > 0 ? cats : false;
    }
});

It’s supposed to be reactive. I know I’ve used it before like this and it worked at the time.

You’re saying the “DISCONNECTED” part never renders when you kill the server?
How long do you wait? (There might be a timeout before it considers the server disconnected)

I wait long enough time to go take a coffee in the street and drink it. I precise that I kill it in dev environment, I didn’t try with deployed production application.

Have you used a {{#if Template.subscriptionsReady}} / {{/if}} around the part of the index.html template you’ve shared? If you have, that will take precedence and mask the connection status.

No I do not, I’ve made a global research on the project’s folder “subscriptionsReady” and 0 results found. As well, if I run it on my android and deactivate the wifi I have the same behavior.

[EDIT]
My if is wrapped by a bigger one which is linked to a db collection. It didn’t work because the app keep locally the data. I will just add a warning somewhere else when offline.

    {{#if categories}}
        <ul class="main">
            {{#each categories}}
                {{> category}}
            {{/each}}
        </ul>
    {{else}}
        <div id="noLinkMessage">
            {{#if is_connected}}
                {{#if is_owner}}
                    You don't have any link yet :(
                {{else}}
                    This user doesn't have any link :(
                {{/if}}
            {{else}}
                DISCONNECTED
                <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
            {{/if}}
        </div>
    {{/if}}

Sorry, my fault

2 Likes