I've run into an incredibly ridiculous bug in my meteor app. Essentially, I have a particular page, that renders a few templates, that crashes Safari on a Mac, and only Safari (and only when the console is NOT open).
I've narrowed it down (somewhat) to a scenario that seem to help fix the problem. Removing event handling on the 'floorList' template listed below. Any thoughts, questions, suggestions would be much appreciated.
I know it's hard to say without seeing everything, but here's roughly the setup:
we're using iron-router, main template loads:
<template name="layout">
<div id="pageWrap">
{{> yield}}
</div>
</template>
our "yield" is a template:
<template name="pageList">
<div class="pages">
{{#each pageWithRank}}
{{> pageItem}}
{{/each}}
</div>
</template>
'pageItem' templates are loaded (limited to return 10 items)
<template name="pageItem">
<div class="page">
...
</div>
</template>
along with a "pageItem" js file that contains helpers and event handlers e.g.:
Template.pageItem.helpers({
...
});
Template.pageItem.events({
'click .shareable': function(e, template) {
...
},
'click .share': function(e, template) {
...
},
'click .removePage': function(e) {
...
}
});
Router Configuration:
var preloadSubscriptions = [];
preloadSubscriptions.push('notifications');
preloadSubscriptions.push('alerts');
preloadSubscriptions.push('myPages');
var mainYieldTemplates = {
'footer': { to: 'footer' },
'header': {to: 'header'}
};
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
yieldTemplates: mainYieldTemplates,
waitOn: function() {
return _.map(preloadSubscriptions, function(sub) {
if (typeof sub === 'object') {
Meteor.subscribe(sub.subName, sub.subArguments);
} else {
Meteor.subscribe(sub);
}
});
}
});
var coreSubscriptions = new SubsManager({
cacheLimit: 10,
expireIn: 1
});
pagesListController = RouteController.extend({
template: 'pageList',
increment: 10,
limit: function() {
return parseInt(this.params.pageLimit) || this.increment;
},
findOptions: function() {
return {
sort: this.sort,
limit: this.limit()
};
},
pages: function() {
return Pages.find({}, this.findOptions());
},
data: function() {
var hasMore = this.pages().count() === this.limit();
return {
pages: this.pages(),
nextPath: hasMore ? this.nextPath() : null
};
},
onBeforeAction: function() {
return [
coreSubscriptions.subscribe('pages', this.findOptions()),
coreSubscriptions.subscribe('pagesListUsers', this.findOptions())
];
}
});
We currently use 6 click events on the item template. Even if they are blank, Safari can crash, removed completely, Safari is fine.
Am I going crazy or doing something terribly wrong with this logic?
EDIT: This also sounds crazy but... by wrapping the templates in the each statement with a div seems to have fixed the problem. why would that be?
{{#each pageWithRank}}
<div>
{{> pageItem}}
</div>
{{/each}}
#each
. Looks like a Blaze bug. – Basutoland