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 followRedirects when source is async and destination is sync #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidtaylorhq
Copy link

The previous implementation of followRedirects() would catch a transition rejection and check the router for an activeTransition. This can become problematic in async situations because the destination transition may have resolved before the reject is scheduled on the previous transition. One such case is when redirecting from an async model hook to a destination route with synchronous model hooks.

This commit updates the followRedirects() logic to explicitly follow the redirect chain rather than relying on the presence of an activeTransition. This makes following redirects work correctly regardless of any scheduling concerns.

This problem has been noted in the context of the visit() test helper:

davidtaylorhq added a commit to davidtaylorhq/ember.js that referenced this pull request Nov 16, 2023
The current implementation of `Transition#followRedirects()` is identical to the logic here: it catches rejections, and then checks for any other `activeTransition`. Therefore, this commit introduces no change in behavior.

But, if/when tildeio/router.js#335 lands, it will means we can take advantage of that fix for ApplicationInstance#visit.
The previous implementation of `followRedirects()` would catch a transition rejection and check the router for an `activeTransition`. This can become problematic in async situations because the destination transition may have resolved before the `reject` is scheduled on the previous transition. One such case is when redirecting from an async model hook to a destination route with synchronous model hooks.

This commit updates the `followRedirects()` logic to explicitly follow the redirect chain rather than relying on the presence of an `activeTransition`. This makes following redirects work correctly regardless of any scheduling concerns.

This problem has been noted in the context of the `visit()` test helper:

- emberjs/ember-test-helpers#332
- emberjs/ember.js#17150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant