Skip to content
This repository has been archived by the owner on Sep 20, 2020. It is now read-only.

$state.go onEnter resolve two times #138

Closed
Pirfox opened this issue Jan 19, 2015 · 6 comments
Closed

$state.go onEnter resolve two times #138

Pirfox opened this issue Jan 19, 2015 · 6 comments
Assignees
Milestone

Comments

@Pirfox
Copy link

Pirfox commented Jan 19, 2015

I have a problem when using $state.go in the onEnter fonction with direct acces to the state via URL, after the redirection eveything is done again. I tried without the lib 'ct-ui-router-extra' and the behavior is gone and it works fine.

To reproduce http://plnkr.co/edit/DjcfKydwRm159sb90xdn
And go to http://run.plnkr.co/7pT8SD2nnQvlrALn/#/top/detail
Everything will be done two times and i don't see why, so if you have any idea how this happens?

Expected output:

top.details
top.list
access details directly

After the two resolves i have what i want, but this is a performance hit when i work on huge list etc

@christopherthielen
Copy link
Owner

confirmed, thanks for the bug report

@christopherthielen
Copy link
Owner

note to self:
root cause is here https://github.com/christopherthielen/ui-router-extras/blob/master/src/futureState.js#L254 due to retrying the initial transition. I'll have to think about what future states requirements are for initial-transition-retry before I can fix this.

            // TODO: analyze this. I'm calling $urlRouter.sync() in two places for retry-initial-transition.
            // TODO: I should only need to do this once.  Pick the better place and remove the extra resync.
            initPromise().then(function retryInitialState() {
              $timeout(function () {
                if ($state.transition) {
                  $state.transition.then($urlRouter.sync, $urlRouter.sync);
                } else {
                  $urlRouter.sync();
                }
              });
            });
          }

@christopherthielen
Copy link
Owner

@Pirfox here's a workaround which effectively disables future states' resync code. I assume you're not using future states?

test.config(function ($futureStateProvider, $stateProvider  , $locationProvider, $urlRouterProvider) {
  $futureStateProvider.addResolve(function($q) { 
    return $q.reject();
  });

@Pirfox
Copy link
Author

Pirfox commented Jan 22, 2015

@christopherthielen Yeah i am not using future states. I will try your proposal in a few days when i am at work. Thank you :)

@Pirfox
Copy link
Author

Pirfox commented Jan 27, 2015

So i am back at work and i could try your solution, it makes the resolve and everything else only once but it disables my $urlRouterProvider.otherwise('/index'); :/

vracini pushed a commit to vracini/ui-router-extras that referenced this issue Jan 27, 2015
@christopherthielen
Copy link
Owner

I don't have time to fix this before 0.0.12. However, 0.0.12 has a modular build, so if you are not using future states, you don't have to include that code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants