-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Don't render route component if OnNavigateAsync task in-progress #24225
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
Conversation
6e66763
to
55b615f
Compare
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit confused by the removal of the try
/finally
here since it looks like if the RunOnNavigateAsync
task fails, then the router would now get stuck permanently, because tcs
would never get marked as completed, and all subsequent navigation tasks will queue up behind it.
However on close inspection it looks like we're saying RunOnNavigateAsync
won't fail, because the only place where we call user code from it is wrapped in a try
/catch
. If that's the reasoning then totally fine! Please let me know if I'm misreading it.
TBH overall I feel that the logic in Perhaps as part of #24215 we could take a fresh run at the whole flow inside BTW I totally understand how we got here through a long chain of evolving changes to requirements and feedback-upon-feedback. Combined with the inherent difficulty of reasoning about concurrent tasks that makes testing hard and review feedback pretty random. It's still great that lazy loading will be in preview 8 and no criticism that we might want to take a fresh look at this one aspect of implementation! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this fix! I know you're out today but hopefully @mkArtakMSFT can take care of merging it into the preview 8 branch.
@mkArtakMSFT Previously I was pushing to include this in preview 8 via ask mode, but after more consideration I think it's not necessary. This change fixes an issue that only affects people who are doing lazy loading (which is only people trying out the feature, since it's new) and even then only when they have a nonstandard routing setup where the host page might rerender independently of routing. So in fact I'd be happy for this just to merge into |
I'm fine with moving this to rc1. I'll update the target branch for this PR accordingly.
This is correct.
My anticipation is that (given proper documentation and awareness for this), it won't happen too often. With this design, we are switching to a cooperative model of cancellation. This comes with a few benefits:
The downside that did come up is the one you mentioned about users being more likely to write bug-ridden code. Ultimately, I felt more comfortable with this model since we anticipate that users leveraging lazy-loading will be more advanced users and I don't anticipate that bugs caused by not throwing the cancellation will be as depilating for them. |
This PR adds a check to the
Refresh
method in the Router class to ensure that a route's component isn't rendered while an OnNavigateAsync method is running.We check the state of the
_previousOnNavigateTask
global which stores a references to the currently running navigation task and only render if it ran to completion.Addresses #24211