Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5982 - Do fetch after route change is complete #7076

Merged
merged 3 commits into from
May 3, 2016

Conversation

Bargs
Copy link
Contributor

@Bargs Bargs commented Apr 27, 2016

Fixes #5982
Fixes #5986

@spalger summed up the root cause of the issue well in #6788:

In order to react to the url changing we listen for the $routeUpdate event on the $rootScope. This event is fired as a part of the transition process before the $location service has flushed it's changes to the browser. Because of this, any changes that happen in the same tick are merged together as a single change. This is generally desirable, but since we are using $location.replace() pretty liberally when the State detects that it has been removed from the URL we need to actually do this in the next tick. This way the $location.replace() call will never be merged with the location change that triggered the update.

This PR takes the same approach, but instead of using undefined behavior in $evalAsync to schedule the query string replacement in the next tick, it simply does the replacement after the route change is complete based on the routeChangeSuccess event.

@spalger
Copy link
Contributor

spalger commented Apr 27, 2016

Oh snap, hope this fixes it! Will take a look soon

@Bargs
Copy link
Contributor Author

Bargs commented Apr 28, 2016

I hope so too! Some design changes in add data have really made this important. The only thing I'm not sure of is if there are any unintended side effects, but I played around with it some and didn't notice any issues.

The one test failure simply asserts that the state object gets destroyed on $routeChangeStart. There's no description why in the commit message though. Looks like @w33ble added the test so he might have some insight into how safe this change is as well.

@Bargs
Copy link
Contributor Author

Bargs commented Apr 28, 2016

If it's not safe to destroy the state in $routeChangeSuccess, I can always create an additional handler for the fetch and leave the destroy action in its current handler.

@w33ble
Copy link
Contributor

w33ble commented Apr 28, 2016

Looks like @w33ble added the test so he might have some insight into how safe this change is as well.

w33ble committed on Sep 30, 2014

Man, that was a long time ago. Back when I had even less of an idea what I was doing than I have now ;)

I suspect I was just trying to make sure that the appState was being cleaned up, not specifically that it was being cleaned up during that event. I think it's safe to update the test to $emit('$routeChangeSuccess') instead, I don't think the actual event matters, just the cleanup.

@spalger
Copy link
Contributor

spalger commented Apr 28, 2016

I can always create an additional handler for the fetch and leave the destroy action in its current handler.

^ this

@Bargs
Copy link
Contributor Author

Bargs commented Apr 28, 2016

Thanks for walking down memory lane @w33ble :)

I left destruction on routeChangeStart since @spalger agreed it was the safer option. Tests should pass now, should be ready for review.

@@ -24,12 +24,16 @@ export default function StateProvider(Private, $rootScope, $location) {
self.fetch();
}),

$rootScope.$on('$routeChangeSuccess', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ super nit approaching ⚠️

can you swap these event handlers so that start comes before success?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your wish is my command :)

Updated.

@spalger
Copy link
Contributor

spalger commented May 2, 2016

LGTM! Now to figure out how far back we should backport this...

@Bargs
Copy link
Contributor Author

Bargs commented May 2, 2016

Good point, @epixa what's our policy on backporting now?

@epixa
Copy link
Contributor

epixa commented May 3, 2016

I wouldn't bother backporting it. The bug has been around for awhile and is a P2. As you pointed out, it's really only a bigger deal now because of the add data ui, which is 5.0+.

@Bargs
Copy link
Contributor Author

Bargs commented May 3, 2016

Works for me.

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

Successfully merging this pull request may close these issues.

4 participants