Click handler triggers Tracker recompute resulting in incorrect/unnecessary path/route change


I’m using Meteor with Blaze and Flow Router. I have a Tracker.autorun setup on the main layout/body template of the app that monitors route changes with Flow Router that looks something like this:

Tracker.autorun(function() {
    var route = FlowRouter.current();
    // stuff happens here...

I’m encountering a situation that seems like an error (at least in the context it’s appearing) in which the following happens:

  1. Mouse click event triggers an event handler that updates a global ReactiveVar
  2. This is eventually handled by setimmediate.js => onGlobalMessage(event)
  3. Tracker._runFlush() gets called
  4. Tracker.Computation._recompute() gets called
  5. Tracker.withNoYieldsAllowed(self._func)(self) gets called
  6. The function returned and called by Tracker.withNoYieldsAllowed(self._func)(self) ends up being the Tracker.autorun function from the snippet of code above

So what that means is: dependencies are recomputed as a result of the click and when this happens Flow Router’s watchPathChange() dependency gets called even though nothing in the resulting handler has affected the application path/route in any way (there are no script changes to document.location.href, no anchor tags have been clicked, no calls to FlowRouter.go(), etc.) - as far as I can tell just the change of the ReactiveVar and the re-running of helpers/templates that depend on it.

Does it seem suspicious that Flow Router’s watchPathChange() dependency is being triggered when only a mouse click event handler has caused a single ReactiveVar to be recomputed and its dependent Blaze templates updated when none of those events affect or change the path/route?

When I look at the route data while debugging it doesn’t seem to have fundamentally changed in any way that is immediately obvious (in other words it seems like a superfluous and unnecessary route change/event that is a duplicate of itself).

So on one hand knowing this is happening I can probably figure out a workaround that watches for and traps this occurrence and the same route firing a change event twice isn’t the end of the world. On the other hand it seems like I should only receive route change events when the route legitimately changes instead of when some random dependency is recomputed.

For anyone familiar with this stuff does this sound like expected behavior or a bug? And if it sounds like a bug does it seem like an issue with Flow Router or with Meteor/Tracker itself?