ground-db icon indicating copy to clipboard operation
ground-db copied to clipboard

Change in Template level autorun behaviour

Open gandev opened this issue 9 years ago • 10 comments

I encountered some problems with the newest ground:db version related to the dispatch:kernel package (which was introduced in v0.3.9). This package causes template.autorun() to rerun after the view is already destroyed! That is causing various problems in our project, especially with autoform and some own components.

gandev avatar May 20 '15 12:05 gandev

Thanks, bugger - this would be nice to work out. Can you give an example of the autorun and where it's initialized?

raix avatar May 21 '15 08:05 raix

@gandev just made a fix for this - can you try updating using dispatch:[email protected] and see if the issue goes away?

raix avatar May 27 '15 13:05 raix

We forked ground:db and removed the kernel call for the moment. But with your fix in place one of the resulting problems (which was easily reproducible) disappeared. I will test some more when the time permits, thank you.

gandev avatar May 28 '15 08:05 gandev

I do have a similar problem (tell me if it is not, I'll open another issue). Every template level autorun triggers the following error:

Exception from Tracker afterFlush function:
Error: Can't call View#autorun from a Tracker Computation; try calling it from the created or rendered callback

The default dispatch:kernel module version is 0.0.6

Here is a minimal example of the code triggering this error:

Template.Example.rendered = function() {
    self=this;
    self.autorun(function(){ //faulty line
           console.log (myReactiveVar.get());
       })
}

Billybobbonnet avatar Nov 02 '15 11:11 Billybobbonnet

Similar problem for me. @gandev's solution works fine

Buom01 avatar Aug 10 '16 19:08 Buom01

@raix with grounddb v2 I still have the same problem.

ilan-schemoul avatar Nov 01 '16 17:11 ilan-schemoul

Template.flowCharting.onRendered(function () {
  $('select').material_select();
  $container = $('#container');
  window.addEventListener('resize', _.debounce(() => jsPlumb.revalidate($('.rect')), 300));

  this.autorun(function () {
    jsPlumb.ready(function () {
      jsPlumb.setContainer('container');
      const source = Template.currentData();
      const data = (source instanceof ReactiveVar) ? source.get() : source;
      clearCharting();
      if (data) {
        rectsRestore(data);
        if (data.userData) rectsRestore(data.userData, true);
      }
    });

    this.autorun(function () {
      const source = Template.currentData();
      const data = (source instanceof ReactiveVar) ? source.get() : source;
      containerEditable();
      if (data) {
        if (isModifiable.get()) everyRectsEditable();
        else rectsNotEditable();
      }
    });
  });
});

Error: Can't call View#autorun from a Tracker Computation; try calling it from the created or rendered callback
    at Blaze.View.autorun (dispatch_kernel.js?hash=0b93ecb…:338)
    at .<anonymous> (flowCharting.js:59)
    at dispatch_kernel.js?hash=0b93ecb…:344
    at Object.Blaze._withCurrentView (blaze.js?hash=a9372ce…:2214)
    at viewAutorun (dispatch_kernel.js?hash=0b93ecb…:343)
    at KernelComputation (dispatch_kernel.js?hash=0b93ecb…:295)
    at Tracker.Computation._compute (tracker.js?hash=f525263…:339)
    at new Tracker.Computation (tracker.js?hash=f525263…:229)
    at Object.Tracker.autorun (tracker.js?hash=f525263…:604)
    at Object.Kernel.autorun (dispatch_kernel.js?hash=0b93ecb…:292)

Is that related to ground:db ???

ilan-schemoul avatar Nov 01 '16 17:11 ilan-schemoul

@NitroBAY it's a shame - I'm thinking we might have to take out the dispatch:kernel... This might hurt performance though.

raix avatar Nov 01 '16 20:11 raix

I have this bug since months and became half crazy, had to use Tracker.autorun() but it has other problems, I didn't know it was related since today and didn't understand why I was the only one who had this bug. Please explain me how the heck no one has ever noticed that this.autorun() oftenly doesn't work when one has ground:db ??

ilan-schemoul avatar Nov 01 '16 23:11 ilan-schemoul

In any way I will be glad you remove it ASAP (to maybe reintroduce it later on ?)

ilan-schemoul avatar Nov 01 '16 23:11 ilan-schemoul