Description
This issue tracker is for Bug Reports and Feature Requests only.
- Bug Report
angularJS: 1.7
My version of UI-Router is: 1.0.17
Bug Report
Current Behavior:
In my project, there is a sideBar which is implemented by $state.go used for change url, and we use lazyload property to load each module. I found that the view will not be updated to the latest state when I click the siderbar very fast to switch url. Due to analysis the trace log and the code of ui-router, I found it is caused by a wrong transition.
when the error occured, the trace log show that there is a A->c transition after A->B;
var activateViews = function (transition) {
var enteringViews = transition.views('entering');
var exitingViews = transition.views('exiting');
if (!enteringViews.length && !exitingViews.length)
return;
var $view = transition.router.viewService;
exitingViews.forEach(function (vc) { return $view.deactivateViewConfig(vc); });
enteringViews.forEach(function (vc) { return $view.activateViewConfig(vc); });
$view.sync();
};
so when A-> started, it will try to remove the viewConfig of A , and the viewConfig of B will left in the _viewConfigs;
var matchingConfigPair = function (uiView) {
var matchingConfigs = _this._viewConfigs.filter(ViewService.matches(uiViewsByFqn, uiView));
if (matchingConfigs.length > 1) {
// This is OK. Child states can target a ui-view that the parent state also targets (the child wins)
// Sort by depth and return the match from the deepest child
console.log(`Multiple matching view configs for ${uiView.fqn}`, matchingConfigs);
matchingConfigs.sort(depthCompare(viewConfigDepth, -1)); // descending
}
return { uiView: uiView, viewConfig: matchingConfigs[0] };
};
Because of the extra config of B, the matchingConfigs will contain B and C, and the viewConfig of B will be returned
Expected Behavior:
the transtion's from state will be the last transition's to state.
question:
- how to avoid the transition mentioned above(A->B, A->C)
- in what situation ,the length of matchingConfigs will be greater than 1(normal situation).
- we try to reverse matchingConfigs first before sort it by depth, and it seem to can get the correct viewConfig, is this solution ok?