You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
View A (say, a modal) adds a history entry, '/foo' when it opens.
View A closes, due to user activation, and the result of that user activation is to synchronously close the modal.
View B (say, another modal, but maybe not) opens, synchronously due to the same user activation, but in code after the effects of (2), and adds a history entry, '/bar' when it opens.
The resulting history, based on the above is [/, /foo, /bar] with the current URL being / rather than what the code might expect, as [/, /bar] with the current URL being /bar.
The reason for this is that navigate requests synchronously resolve, regardless of existing traversal requests.
For traversals, the navigation event and the transition property are called and populated asynchronously. Meaning that immediately after a call to navigation.traverseTo we have no ability to detect that a traversal is occurring and we might want to wait for it to commit (or cancel).
We work around this issue in the existing API only partially, but essentially if a user requests a traversal in JS, we wait for the next popstate to ensure that the traversal has resolved before we allow further requests to the browser to change history. So, we queue up push navigations until ready.
Proposed resolution:
My proposal is:
Synchronously expose information about pending traversals so that the router can choose whether to wait for or cancel existing traversals.
This would move the code that currently has to wait for existing traversals before navigate() can be called into the navigate handler, which would catch any and all calls to navigate.traverseTo and history.back.
The text was updated successfully, but these errors were encountered:
I'm guessing that's not an option in your case, e.g. because the third line is located somewhere else in the codebase where the return value of navigation.traverseTo() is not easy to access.
And indeed, it sure seems like navigation.transition was intended to be helpful here. Then the code could look something like
which is nice and easy to divvy up into multiple disconnected files. And indeed, if we work on #66, you could add the await navigation.transition.finished inside the navigate handler, so that your original code works as-is with no workarounds.
So I think this is a matter of ensuring we populate navigation.transition the moment a traversal is requested, instead of the moment it actually starts. That seems reasonable to me.
Here is an example of something we do in our applications:
A concrete example of this is:
The resulting history, based on the above is [/, /foo, /bar] with the current URL being / rather than what the code might expect, as [/, /bar] with the current URL being /bar.
The reason for this is that navigate requests synchronously resolve, regardless of existing traversal requests.
For traversals, the navigation event and the transition property are called and populated asynchronously. Meaning that immediately after a call to
navigation.traverseTo
we have no ability to detect that a traversal is occurring and we might want to wait for it to commit (or cancel).We work around this issue in the existing API only partially, but essentially if a user requests a traversal in JS, we wait for the next popstate to ensure that the traversal has resolved before we allow further requests to the browser to change history. So, we queue up push navigations until ready.
Proposed resolution:
My proposal is:
This would move the code that currently has to wait for existing traversals before navigate() can be called into the navigate handler, which would catch any and all calls to navigate.traverseTo and history.back.
The text was updated successfully, but these errors were encountered: