Skip to content
New issue

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

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

Already on GitHub? # to your account

Handle races between user actions and transitions #479

Closed
gaearon opened this issue Nov 18, 2014 · 2 comments · Fixed by #480
Closed

Handle races between user actions and transitions #479

gaearon opened this issue Nov 18, 2014 · 2 comments · Fixed by #480

Comments

@gaearon
Copy link
Contributor

gaearon commented Nov 18, 2014

Router currently doesn't handle races between user actions and transitions well.

Say I'm on route /good, and /slow handler has this code (assuming abort() is fixed of course):

statics: {
  willTransitionTo(transition, params) {
    transition.wait(Promise.delay(3000).then(() => transition.abort()));

If I click a link to /slow, URL will change to /slow and will wait three seconds before going back to /good (because of aborted transition).

However if I click a link to /slow and then perform a Back myself (which will immediately change address to /good), the router will still invoke goBack, potentially throwing me out of the website.

Similarly, if I get tired of waiting and click a link to /another, when /slow is ready and its transition.abort() runs, it will force going back when I'm neither on /good nor on /slow anymore.

This is not just a problem with abortions: even if I just have a slow transition.wait() and click on a link while I'm waiting for transition to happen, router will happily take me there, but then all of a sudden will force the transition on me.

I propose the following rule of thumb for solving race problems in router: user intent must always override pending transitions. In other words, user clicking Back or clicking on a link should abort the pending transition. This behavior is most natural and matches what browser does.

I'm preparing a PR for that.

@ryanflorence
Copy link
Member

I propose the following rule of thumb for solving race problems in router: user intent must always override pending transitions.

Agreed, can't wait for the PR :)

@gaearon
Copy link
Contributor Author

gaearon commented Nov 24, 2014

It's actually there (#480) but not rebased yet. I think I can rebase tomorrow.

gaearon added a commit to gaearon/react-router that referenced this issue Nov 26, 2014
Previously, navigating (by clicking Back button or a link) while a transition in progress would put router into an inconsistent state.
Now, a pending transition will be aborted and ignored by the router if user navigates away while it was pending.

Fixes remix-run#479
@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants