aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 138 forks source link

Problem with isVisible template helper #116

Open zimme opened 9 years ago

zimme commented 9 years ago

When using reactive table in 2 different routes when switching from one to the other i get this stack trace

Exception in template helper: TypeError: Cannot read property 'get' of undefined
    at Object.Template.reactiveTable.helpers.isVisible (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:783:39)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18)
    at http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:97:24
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18)
    at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) debug.js:41
Exception in template helper: TypeError: Cannot read property 'get' of undefined
    at Object.Template.reactiveTable.helpers.sortedRows (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:792:47)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18)
    at http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:224:22
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2503:27)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18)
    at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) debug.js:41
Exception in template helper: TypeError: Cannot read property 'get' of undefined
    at Object.Template.reactiveTable.getPageCount (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:743:39)
    at Object.Template.reactiveTable.helpers.showNavigation (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:850:52)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18)
    at Template.reactiveTable.Blaze.If.HTML.DIV.class (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:258:22)
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18) debug.js:41
Exception from Tracker recompute function: Error: Can't call non-function: undefined
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:172:13)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:106:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:110:39)
    at HTML.TR.class (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:228:26)
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
    at Blaze._HTMLJSExpander.def.visitAttribute (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1958:21)
    at HTML.TransformingVisitor.def.visitAttributes (http://localhost:3000/packages/htmljs.js?539b5fc23cf5e63bc8e324543a1026b138316a8c:228:44)
    at Blaze._HTMLJSExpander.def.visitAttributes (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1952:63)
    at Object.Blaze._expandAttributes (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1981:32)
    at updateAttributes (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1465:35) debug.js:41
Exception in template helper: TypeError: Cannot read property 'get' of undefined
    at Object.Template.reactiveTable.helpers.isVisible (http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:783:39)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18)
    at http://localhost:3000/packages/aslagle_reactive-table.js?3ae92127b727852bebc5cf5db5b799513c48fe1a:234:26
    at null.<anonymous> (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44)
    at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18)
    at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) 
jpmolinamatute commented 9 years ago

same here!

aslagle commented 9 years ago

I think it's re-rendering a template instance and overwriting the data context set up in Template.created. But in all my testing it seemed to persist across reactive re-renderings. Could one of you share your routing setup so I can try to reproduce this?

jpmolinamatute commented 9 years ago

my routing setup is very simple:

Router.configure({ loadingTemplate: 'loading', notFoundTemplate: 'notfound', layoutTemplate: 'main' });

Router.map(function () {

this.route('master', {
    path: '/',
    layoutTemplate: 'main',
    yieldTemplates: {
        'SidebarContents': {
            to: 'sidebarContents'
        },
    }
});

this.route('frameworks', { path: '/frameworks', layoutTemplate: 'main', yieldTemplates: { 'frameworksSidebarContents': { to: 'sidebarContents' }, } });

this.route('framework_detailed', { path: /^\/framework\/(\d+)-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)/, layoutTemplate: "framework_detailed" });

this.route('log', {       
    path: /^\/log\/(\d+)/,
    layoutTemplate: "log"
});

});

I'm having the problem when I go from /framework to /framework-20141007-200657-251789322-5050-14183-0000

aslagle commented 9 years ago

Thanks! Is the data in your table based on the numbers in the path?

aslagle commented 9 years ago

Please try out 0.5.1 and let me know if it fixes the error. I'm not that happy with the change but I think it works... hard to reproduce this consistently though :)

zimme commented 9 years ago

Working for me. When I have some time I'll try and help out with making a "cleaner" version of the change =)

jasonxeno commented 9 years ago

I had this same error, and 0.5.1 has fixed it for me, thanks.

sclausen commented 9 years ago

it works in 0.5.2 but in 0.5.3 its broken again

aslagle commented 9 years ago

Sorry about that. It should be fixed in 0.5.4.

sclausen commented 9 years ago

wow, that was fast :+1: many thanks!!!!

sys13 commented 9 years ago

Still getting this error on 0.5.4

aslagle commented 9 years ago

Sorry, there are a couple separate bugs here.. try 0.5.5, fingers crossed :)

sys13 commented 9 years ago

Still have it with 0.5.5. Looks like a stubborn one :)

aslagle commented 9 years ago

Are you getting the same stack trace as above, or only the isVisible part?

sys13 commented 9 years ago

Only the isVisible part.

Exception in template helper: TypeError: Cannot read property 'get' of undefined at Object.Template.reactiveTable.helpers.isVisible (http://localhost:3000/packages/aslagle_reactive-table.js?f8086358ed785564ac05094c0ae1cf68ac660677:805:39) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16 at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16 at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18) at http://localhost:3000/packages/aslagle_reactive-table.js?f8086358ed785564ac05094c0ae1cf68ac660677:99:24 at null. (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16 at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12) at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18) at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)

aslagle commented 9 years ago

And which part of the table isn't working? Are the rows showing?

sys13 commented 9 years ago

Don't see any side effects (besides making the page look like it has errors in IE). Everything seems to be working.

aslagle commented 9 years ago

That's strange. Maybe it's initially missing the settings, and then re-renders.

jpmolinamatute commented 9 years ago

I'm getting the same error message as @sys13, I'm using V. 0.5.5

hellogerard commented 9 years ago

FWIW, I had this same error on 0.5.0. Upgrading to 0.5.5 fixed it for me (I wasn't using it on two different routes though).

hbrunner commented 9 years ago

I'm having the same issue on 0.5.5 on one view.

Exception in template helper: TypeError: Cannot read property 'get' of undefined at Object.Template.reactiveTable.helpers.isVisible (http://localhost:3000/packages/aslagle_reactive-table.js?cab9a5ad9912f7775039087d2b4f2a80c12d8364:805:39) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16 at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16 at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18) at HTML.LI.HTML.A.HTML.LABEL.Blaze.If.HTML.INPUT.type (http://localhost:3000/packages/aslagle_reactive-table.js?cab9a5ad9912f7775039087d2b4f2a80c12d8364:205:26) at null. (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16 at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12) at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18) at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)

zimme commented 9 years ago

It seems this happens now when you try and render a table with an empty collection. i.e. parentData(1) or parentData(2) don't exists.

aslagle commented 9 years ago

Those of you seeing this in 0.5.5, does anyone have a public repo or app I could take a look at?

jpmolinamatute commented 9 years ago

FWIW, I'm using v. 0.5.6, I'm using several instances of this templates and so far I get this error only in one of those interfaces in one specific case. I click on a row. I also have some code for the click event in "tbody tr". First time I click on a row it works perfect, as expected, the second time that I click in any row I got this error (at least 22 times at once).

Exception in template helper: TypeError: Cannot read property 'get' of undefined at Object.Template.reactiveTable.helpers.isVisible (http://localhost:3000/packages/aslagle_reactive-table.js?ea00290ae77ff9c2d8eb60e2296b471da2b7e490:810:39) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16 at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16 at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18) at HTML.LI.HTML.A.HTML.LABEL.Blaze.If.HTML.INPUT.type (http://localhost:3000/packages/aslagle_reactive-table.js?ea00290ae77ff9c2d8eb60e2296b471da2b7e490:205:26) at null. (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44) at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16 at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12) at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18) at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)

So I followed the link http://localhost:3000/packages/aslagle_reactive-table.js?ea00290ae77ff9c2d8eb60e2296b471da2b7e490:810:39

and I think for some reason topLevelData is either undefined or has the wrong object. I hope this helps you at least a little

epaminond commented 9 years ago

An error still can be reproduced on 0.5.8 release.

epaminond commented 9 years ago

For me an error occurs only in case topLevelData gets Template.parentData(1); value which in this case isn't a reactiveTableSetup. It seems to be an object of params that are passed to reactiveTable template. For example I have {{> reactiveTable collection=matchedContacts settings=settings }} and topLevelData becomes {collection: Array[1], settings: Object}.

When I define visibleFields property manually and pass it to reactiveTable template alongside with other params it gets used in this case.

aslagle commented 9 years ago

That confirms that setup isn't running before isVisible gets called. You shouldn't need to pass in visibleFields - it will be replaced if setup runs.

If you want to fix it, you could try having isVisible return false if both Template.parentData(2) and Template.parentData(1) don't have reactiveTableSetup. It would give you a table with no columns, but maybe setup would run afterward and the table would re-render. You could also try calling setup from more places. I still can't reproduce this so I won't be able to tell if it works.

epaminond commented 9 years ago

setup function indeed runs after isVisible helper is accessed.

epaminond commented 9 years ago

An error flow is as follows:

  1. Reactive table runs first time and rendered event runs setup
  2. isVisible helper runs without any errors
  3. after some time isVisible helper is fired again and an error occurs
  4. setup get's fired from setup helper

It looks like helpers not necessarily run one after another as defined in a template.

aslagle commented 9 years ago

After #4, does isVisible run again? That would probably make it easier to fix.

epaminond commented 9 years ago

@aslagle yes isVisible runs again after setup on the fourth stage.

aslagle commented 9 years ago

Ok, I published version 0.5.10-alpha1 which might fix this, but it also might give you an empty table instead. Try it out and let me know if it helps. It's a pre-release so I think you'll have to manually set the version.

jasonxeno commented 9 years ago

0.5.10-alpha1 renders only an empty table for me.

On Wed, Dec 17, 2014 at 7:54 AM, Amy Slagle notifications@github.com wrote:

Ok, I published version 0.5.10-alpha1 which might fix this, but it also might give you an empty table instead. Try it out and let me know if it helps. It's a pre-release so I think you'll have to manually set the version.

— Reply to this email directly or view it on GitHub https://github.com/ecohealthalliance/reactive-table/issues/116#issuecomment-67324698 .

epaminond commented 9 years ago

Seems to work fine for me.

aslagle commented 9 years ago

Hmm.. maybe there's still more than one bug. I have another idea but it'll be harder to implement.

aslagle commented 9 years ago

In 0.5.10, I've switched back to a with statement and set up a separate template instance variable instead of template.data. I think it will fix at least one cause of this error :)

epaminond commented 9 years ago

Indeed error doesn't come up on 0.5.10 for me.

jasonxeno commented 9 years ago

0.5.10 has completely fixed the error for me. Good detective work @aslagle, thank you!