Meteor exception in Meteor.flush when updating a collection breaks reactivity across clients

Posted by Harel on Stack Overflow See other posts from Stack Overflow or by Harel
Published on 2012-11-19T17:00:05Z Indexed on 2012/11/22 17:00 UTC
Read the original article Hit count: 268

Filed under:
|

When I'm calling Collection.update from the front end (the method call is allowed), the update does work ok, but the exception below is being thrown (in Chrome's JS console, not in the server). Although the update took place, other clients connected to the same collection do not see the updates until they refresh the browser - I suspect because of the exception.

Any idea what might cause this?

Exception from Meteor.flush: Error: Can't create second landmark in same branch
    at Object.Spark.createLandmark (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1085:13)
    at http://checkadoo.com/packages/templating/deftemplate.js?7f4bb363e9e340dbaaea8d74ac670af40ac82d0a:115:26
    at Object.Spark.labelBranch (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1030:14)
    at Object.partial [as list_item] (http://checkadoo.com/packages/templating/deftemplate.js?7f4bb363e9e340dbaaea8d74ac670af40ac82d0a:114:24)
    at http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:349:48
    at Object.Spark.labelBranch (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1030:14)
    at branch (http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:308:20)
    at http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:348:20
    at Array.forEach (native)
    at Function._.each._.forEach (http://checkadoo.com/packages/underscore/underscore.js?772b2587aa2fa345fb760eff9ebe5acd97937243:76:11) 

EDIT Here is my template for the clickable item that triggers the update:

<template name="list_item">
  <li class="checklistitemli">
  <div class="{{checkbox_class}}" id="clitem_{{index}}">
    <input type="checkbox" name="item_checked" value="1" id="clcheck_{{index}}" class="checklist_item_check" {{checkbox_ticked}}> {{title}}
  </div>
  </li>
</template>

and here's the event handler for clicks on 'list_item':

var visualCheck = function(el, checked) {
  var checkId = el.id.replace('clitem','clcheck');
  if (checked) {
    addClass(el, 'strikethrough');
    $('')
  } else {
    removeClass(el, 'strikethrough');
  }
  $('#'+checkId)[0].checked=checked;  
}; 


Template.list_item.events = {
  'click .checklistitem' : function(ev) {
    this.checked = !this.checked;
    var reverseState = !this.checked;
    var updateItem = {},
        self = this,
        el = ev.target;
    visualCheck(el, this.checked);  
    updateItem['items.'+this.index+'.checked'] = this.checked; 
    console.log("The error happens here");
    Lists.update({_id: this._id}, {$set:updateItem}, {multi:false} , function(err) { 
      console.log("In callback, after the error");
      if (err) {
        visualCheck(el, reverseState);
      }
    });
  }
}

The whole thing is available at http://checkadoo.com (Its a port of a Tornado based Python app of mine)

© Stack Overflow or respective owner

Related posts about node.js

Related posts about meteor