Repository navigation
refactor(router): compute correct history restoration when navigation is cancelled - #38884
aahmedayed wants to merge 1 commit into
Conversation
e2b10a5 to
add1b74
Compare
atscott
left a comment
There was a problem hiding this comment.
Hi @aahmedayed - this looks promising! What do you think of breaking this up into two PRs? I think a PR to add go/goTo as a feature separately would be valuable on its own. Then have a separate PR to fix the routing history with guards. This would make the review process much easier.
I haven't reviewed the changes to the router yet, as that will take a little more time and careful review.
|
Hi @atscott - thank you for your review, and yes i think it’s a good idea to have the solution into two PR’s. |
6e7416a to
894f5d0
Compare
|
Hi @atscott - I’ve already finished the adjustments. |
atscott
left a comment
There was a problem hiding this comment.
This is looking better :) I've added another round of comments.
I think you may have missed one of my comments about a request to add some more testing around the history in some scenarios:
- An error during navigation (this was why we moved some logic to
finalize) - a route being cancelled by a canLoad guard
- a route being cancelled by a resolver returning
EMPTY
|
Adding the |
4a1fb91 to
524762e
Compare
|
Hi @atscott i made the requested changes. |
|
@aahmedayed Thanks, I'll take another look today. I think we should not include e3da2c6 because it would make this TODO even harder to resolve. It might be that it's something that doesn't make sense to change anymore but we should limit the changes in this PR to what's absolutely necessary to accomplish our goal here. |
atscott
left a comment
There was a problem hiding this comment.
Another round of comments with one noticeable bug.
Sorry, I know this has been a ton of work for you but you're doing a really great job here! This change is incredibly complex with a lot of moving parts and edge cases to test.
There was a problem hiding this comment.
I would prefer not adding ngRouterPageId here because it makes it more public than I would want. Accessing it is still possible even without it because of the {[k: string]: any}. I don't think navigationId should ever really have been included here because it makes the public API more confusing since "navigationId" wasn't meant to be public in this way.
There was a problem hiding this comment.
Maybe this was missed in one of the squashes. Let's remove ngRouterPageId here so we don't change the public API.
There was a problem hiding this comment.
Could you add the else case with a comment as to why it's a no-op?
There was a problem hiding this comment.
Unresolving. Please add the else case and add a comment as to why nothing is done there (if update is not 'eager', then the navigation was cancelled before any browser url change so nothing needs to be restored).
|
Hi @atscott, no problem at all, I’ll take care of it ASAP. |
|
Hi @aahmedayed, have you gotten a chance to address the last round of feedback? I have some ideas that would allow us to merge this as a non-breaking change after you've pushed your latest updates. |
|
Hi @atscott, I'll try to finish with the requested changes this week at the latest. |
|
Hi @atscott, I'm done with the requested changes, but i think we can't do this #38884 (comment) change now because the test_ivy_aot failed and the error is that cannot find name |
atscott
left a comment
There was a problem hiding this comment.
@aahmedayed thanks for the updates! I'll take a look at the changes this week. No problem on the @internal comment.
My plan for landing this change is:
- Submit the change first without a public API option so we can continue to test and offer the solution to the interested parties on the bug as a private preview (the option in the Router will be set to
@internalbut users can opt-in with(Router as any).canceledNavigationResolution = 'computed'). We can consider a follow-up change to add it as public in a minor version. - Move the changes to
location_mockinto a local copy used by the router tests. This avoids making this a breaking change and we can remove it when #41730 is submitted. - clean up the commits: squash most/all of them into a single commit and update the commit message(s)
- Move the commit that updated the
navigationIdandpageIdto be in thengnamespace to a follow-up PR (again to avoid making this a breaking change). I like this change but it would prevent us from submitting this until v13.
Sorry for requesting reverts to changes I had you do; we should get them merged eventually, but getting this PR submitted sooner rather than later (in v13) seems like a good idea. Do you mind if I make those changes and push up to your branch as a co-author or would you like to do the updates yourself?
|
Ok @atscott there is no probleme, I start making those changes right now. But I'm not sure I understand the second point correctly. Can you please provide me with more details ? Thank you. |
|
@aahmedayed - Absolutely. There are changes here that depend on your updates to the back/forward methods in |
|
Ah ok! I understand, thank you @atscott |
|
Hi @atscott - I'm done with the requested changes. |
atscott
left a comment
There was a problem hiding this comment.
Looking good. A few more minor comments. Also, can you amend the commit message to be:
refactor(router): compute correct history restoration when navigation is cancelled
We can’t determine whether the user actually meant the `back` or
the `forward` using the popstate event (triggered by a browser back/forward)
so we instead need to store information on the state and compute the
distance the user is traveling withing the browser history.
So by using the `History#go` method,
we can bring the user back to the page where he is supposed to be after
performing the action.
We should change the scope of this commit to be a refactor since we haven't provided a public API for the fix (so nothing was actually fixed yet). We should also remove the fix # comment since, again, we haven't made the fix available.
There was a problem hiding this comment.
Maybe this was missed in one of the squashes. Let's remove ngRouterPageId here so we don't change the public API.
|
Hi @atscott - I'm done with the requested changes. |
atscott
left a comment
There was a problem hiding this comment.
LGTM with two minor comments on the state restoration function.
reviewed-for: public-api
reviewed-for: size-tracking
There was a problem hiding this comment.
Unresolving. Please add the else case and add a comment as to why nothing is done there (if update is not 'eager', then the navigation was cancelled before any browser url change so nothing needs to be restored).
jessicajaniuk
left a comment
There was a problem hiding this comment.
LGTM 🍪
reviewed-for: size-tracking
|
Hi guys, i have finished the changes that have been asked of me, but i haven’t had the chance to work on the docs since i’m having a very busy week. |
… is cancelled We can’t determine whether the user actually meant the `back` or the `forward` using the popstate event (triggered by a browser back/forward) so we instead need to store information on the state and compute the distance the user is traveling withing the browser history. So by using the `History#go` method, we can bring the user back to the page where he is supposed to be after performing the action. implementation for angular#13586
AndrewKushnir
left a comment
There was a problem hiding this comment.
@aahmedayed thanks for addressing the feedback, the changes look good 👍
|
another presubmit for a sanity check |
|
You're the most welcome @AndrewKushnir and thanks a lot @atscott |
|
Hi @aahmedayed, I had a thought tonight about this and realized we missed a pretty important scenario. It's very common for guards to schedule a new navigation before returning A specific scenario where this doesn't work:
There might be other scenarios I haven't thought of. I'll be on vacation until July. If you get a chance to take a look and send a PR before then, I can review it when I'm back. Otherwise I'll see about investigating other scenarios, making some adjustments to the code, and then start thinking about making the option public opt-in. |
|
@aahmedayed I've been working with this more today and I'm a little concerned that this won't work in the end. We can always figure out how to handle things when navigations go through the back/forward buttons or through Edit: Playing with this in a real application, it seems like browsers retain information about the origin of the navigation. This means that if I am going between pages that cross a manual navigation boundary, it treats that as a non-SPA navigation so the |
|
HI @atscott - Sorry for the delay I’m taking some days off, I’ll be back Monday. Thank you for all the fixes you made. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We can’t determine whether the user actually meant the
backorthe
forwardusing the popstate event (triggered by a browserback/forward)
so we instead need to store information on the state and compute the
distance the user is traveling withing the browser history.
So by using the
History#gomethod,we can bring the user back to the page where he is supposed to be after
performing the action.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information