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

isReady() never resolves or errors if a guard prevents initial navigation #1305

Closed
danielroe opened this issue Feb 12, 2022 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@danielroe
Copy link
Member

Version

4.0.12

Reproduction link

jsfiddle.net/qxt3dpom/24/

Steps to reproduce

Run - and observe that we never resolve .isReady(), and therefore vue never mounts.

What is expected?

Ideally a failure to resolve would be 'catchable' in some way.

What is actually happening?

isReady neither resolves nor throws

@posva
Copy link
Member

posva commented Feb 13, 2022

The question is what should happen in this scenario? should isReady() reject? Or should it resolve with the failure as the resolved value (like router.push)?

@danielroe
Copy link
Member Author

It's a tricky one - and I'm persuadable either way. But the documentation describes isReady as:

Returns a Promise that resolves when the router has completed the initial navigation, which means it has resolved all async enter hooks and async components that are associated with the initial route.

Given that, I think we can treat a failure to complete the initial navigation as an error. (Future failures to complete navigation wouldn't be errors.) What do you think?

@posva
Copy link
Member

posva commented Feb 14, 2022

I agree. Let's try to still get a little more feedback on this

@posva
Copy link
Member

posva commented Feb 22, 2022

final thoughts:

  • isReady() should reject if an initial navigation returns false
  • Pushing again after a rejection and calling isReady() after an initial failed navigation, should yield a new promise:
    // arrives at /admin and navigation guard returns false (it could also redirect but this is not the case in this scenario)
    router.isReady().catch((error: Error | NavigationFailure) => {
      router.push('/home') move the user to a different safe location
      return router.isReady() // we can return a new promise (only valid after calling a new push)
    }).then(...)

@posva posva closed this as completed in 509fc0d Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants