Hi,
TLDR: In my template file, the Template.subscriptionsReady is returning true and rendering even though the subscription is not ready.
I am having an issue with template level subscriptions, in that the Template.subscriptionsReady helper function is firing immediately.
Here is what is inside my template for loading an image.
<template name="cards_image">
{{#if Template.subscriptionsReady}}
<img class="detail__caption__media__image" data-src="{{mediaUrl}}/{{image.filename}}" width="100%" height="auto" alt="" />
{{else}}
<p>Wait!</p>
{{/if}}
</template>
What I would expect to happen here is that the message ‘Wait!’ is displayed and then the image is displayed only when the image helper function I am using is ready. For reference, my controller is below.
What is actually happening is that the code is loading the img tag as if the subscription is ready, and completely ignoring the second case to display the message, despite the fact that the template is not yet ready grabbing the data from the image helper, it behaves as if it is.
'use strict';
/**
* Template.cards_image
* Callback function called automatically when the template has been created
*
* @method created
*/
Template.cards_image.onCreated(function() {
// Adding this in as a fake delay to highlighte the issue
setTimeout(() => {
//also tried this.subscribe('images', this.data.sys.id);
Meteor.subscribe('images', this.data.sys.id);
}, 5000);
});
/**
* Template.cards_image
* Callback function called automatically when the template has been rendered
*
* @method rendered
*/
Template.cards_image.onRendered(function() {
let target = this.$('img').get(0);
this.autorun(() => {
Dependencies.scrolled.depend();
Core.helpers.lazyLoad(target);
});
});
/**
* Template.cards_image
* Callback function called automatically when the template has been destroyed
*
* @method destroyed
*/
Template.cards_image.onDestroyed(function() {
});
/**
* Template.cards_image
* Helper functions
*/
Template.cards_image.helpers({
image () {
Dependencies.resized.depend();
let selector = {
'asset_id': this.sys.id,
'device': Device.name,
'density.multiplier': Device.pixelRatio
};
return Core.collections.images.findOne(selector);
}
});
For reference, the entire project is on GitHub at - https://github.com/matfin/annachristoffer/tree/lazyload
Has anyone else encountered this issue and if so, how did you solve it?