Skip to content

Commit

Permalink
Fix crazy context switching issue
Browse files Browse the repository at this point in the history
In the commit: 05f09f4 we introduce a new way to handle
multiple conytexts at once.
But that leads to crazy issue where showing different context
for the URL above.
So basically, you'll visit a page A, but you'll get page B
Then we had bring back Tracker.flush with some guarding for errors
  • Loading branch information
arunoda committed Jun 26, 2015
1 parent 41b841d commit 6ca54cc
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ Router = function () {

this._tracker = this._buildTracker();
this._current = {};
// It's possible that, more than one context is processing at a give time
// This is used for running action handler
// by putting them into an array allow us to handle them in order
// If we get the context via `this._current`,
// it may not be the correct context
//
// See "redirect from enter" test case for a good example
// It first redirect to "/" and into a another route.
// Second route's action should not be called, but it's calling
// because of the "/" route.
this._processingContexts = [];

// tracks the current path change
this._onEveryPath = new Tracker.Dependency();
Expand Down Expand Up @@ -374,7 +363,7 @@ Router.prototype._buildTracker = function() {
}

// see the definition of `this._processingContexts`
var currentContext = self._processingContexts.shift();
var currentContext = self._current;
var route = currentContext.route;
var path = currentContext.path;

Expand Down Expand Up @@ -430,9 +419,25 @@ Router.prototype._buildTracker = function() {

Router.prototype._invalidateTracker = function() {
this.safeToRun++;
// see the definition of `this._processingContexts`
this._processingContexts.push(this._current);
this._tracker.invalidate();
// After the invalidation we need to flush to make changes imediately
// otherwise, we have face some issues context mix-maches and so on.
// But there are some cases we can't flush. So we need to ready for that.

// we clearly know, we can't flush inside an autorun
// this may leads some issues on flow-routing
// we may need to do some warning
if(!Tracker.currentComputation) {
// Still there are some cases where we can't flush
// eg:- when there is a flush currently
// But we've no public API or hacks to get that state
// So, this is the only solution
try {
Tracker.flush();
} catch(ex) {

}
}
};

Router.prototype._updateCallbacks = function () {
Expand Down

0 comments on commit 6ca54cc

Please # to comment.