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(nuxt): abort navigation when updating window.location
#21521
Merged
danielroe
merged 3 commits into
nuxt:main
from
nicolaspayot:fix/navigateTo-external-middleware-csr
Jun 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f668d32
fix(nuxt): abort navigation when redirecting to external link from miβ¦
nicolaspayot 6762d95
fix(nuxt): when app is hydrating, navigation should not be aborted frβ¦
nicolaspayot 5be9e78
Merge branch 'main' into fix/navigateTo-external-middleware-csr
danielroe File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is a corner case that's not handled here: when the Nuxt app is loaded on a route that has a redirect middleware. The page gets rendered (and is visible during a very short time) before the location changes. If we also return
false
whennuxtApp.isHydrating
, it renders a 404 error / page (that's visible during a very short time).There's something we could do: delay the return statement, like so, for example:
But it looks a bit hacky π€
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 wonder what happens if you return a never-resolving promise π€
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 actually think that's what's happening with
return new Promise(resolve => setTimeout(resolve, 10))
as the location changes before theresolve
function gets called.I like the idea of returning a never-resolving promise (
return new Promise(() => {})
) for this case π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.
@danielroe I've pushed the change. Let me know if this is acceptable. I can't see a case when this would lead to an issue. Maybe if, somehow,
location.href = toPath
orlocation.replace(toPath)
fail but can this happen?