Don't understand the circumstances under which getMeteorData is triggered


#1

I was under the impression that if any reactive variables used within getMeteorData change, then getMeteorData will fire off. But I’m getting stuck in an infinite loop for some reason, and I don’t see how it’s happening. I’m using meteorflux:dispatcher BTW.

I’ve got a dashboard which will run a query to Salesforce but only if we’re connected to the service.

Dashboard = React.createClass({
  displayName: 'Dashboard',
  mixins: [ReactMeteorData],

  getMeteorData() {
    if (Store.isSfConnected()) {
      Dispatcher.dispatch({
        action: 'USER_REQUESTED_DATA_REFRESH'
      });
    }

    return {
      sfConnected: Store.isSfConnected(),
      eventsList: Events.find({}, {sort: {StartDateTime: 1}}).fetch()
    }
  },
  [...]

The only reactive variables that the USER_REQUESTED_DATA_REFRESH function is modifying are these:

    appState.set({
      queryDone: false,
      queryInProgress: true
    });

   [...]

    Events.remove({}); // clear out any data first
    _.sortBy(finalResults, 'StartDateTime').forEach(function (event) {
      Events.insert(event);
    });

  [...]

    appState.set({
      queryDone: true,
      queryInProgress: false
    });

Events is getting updated in a loop… but my console.log statement in the dashboard that dumps the contents shows it’s already fully populated. And even if I remove Events.insert, I’m still in a loop.

I’m stumped. I wish I could trace this better, and it’s too bad getMeteorData can’t tell me which reactive state change triggered it. I’d step through the Chrome debugger, but I don’t want to step through all the guts of the Meteor library (Chrome’s blackboxing appears to be broken). How do I go about troubleshooting this?


#2

I’ve commented out all reactive parts of getMeteorData in the dashboard except this:

    if (Store.isSfConnected()) {
      Dispatcher.dispatch({
        action: 'USER_REQUESTED_DATA_REFRESH'
      });
    }

There’s no way the state of isSfConnected is changing like that. It’s only set once upon connection.


#3

I was also stuck in an infinite loop. Then I found out that getMeteorData depends on state and re-runs whenever state changes. See here: https://github.com/meteor/react-packages/issues/71
I guess this is the problem that you are facing, too. Could it be the case that your getMeteorData depends on the state that USER_REQUESTED_DATA_REFRESH sets?