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

Middleware(s) sometimes not executing on double browser back navigation #6716

Closed
jsonpoindexter opened this issue Nov 21, 2019 · 1 comment
Closed

Comments

@jsonpoindexter
Copy link

jsonpoindexter commented Nov 21, 2019

Version

v2.10.2

Reproduction link

https://github.com/jsonpoindexter/nuxt-middleware-test

Steps to reproduce

  1. Navigate to http://localhost:3000/a
  2. Use "Go to page B' nuxt-link to navigate to http://localhost:3000/b
  3. On http://localhost:3000/b either use Go To External link to navigate to an external link, or navigate directly to an external link via the browser
  4. From the external site: press the browsers Back button twice

What is expected ?

User should land on /a and the anonymous middleware for page a should execute and display:"[a] ANON MIDDLEWARE" in the console

Pressing back button two times in quick succession:
middleware-executing.jpg

Pressing back button once to get back to page B, and then once again after page B has loaded:
middleware-executing-2.jpg

What is actually happening?

If the second browser click back was executed while page B was loading the middleware for page A will not execute.

middleware-not-executing.jpg

Additional comments?

I seem to only be able to reproduce this issue on slower machines. On faster machines it is near impossible for me to execute the second browser back click while page B is loading.

As stated above I am also only able to reproduce this (on slower machines) if the second browser Back button is executed before page B's mounted life cycle can run.

@ghost ghost added the cmty:bug-report label Nov 21, 2019
@jsonpoindexter jsonpoindexter changed the title Middleware(s) not executing on browser back navigation Middleware(s) not executing on double browser back navigation Nov 21, 2019
@jsonpoindexter jsonpoindexter changed the title Middleware(s) not executing on double browser back navigation Middleware(s) sometimes not executing on double browser back navigation Nov 21, 2019
@jsonpoindexter
Copy link
Author

It looks like what is happening is that the server side code is executed for the first navigation back to the app (page B) and then the client side code is being executed on the second page navigation back to the app (page A) thus skipping middleware execution for page A since:

In universal mode, middlewares will be called server-side once (on the first request to the Nuxt app or when page refreshes) and client-side when navigating to further routes.

https://nuxtjs.org/guide/routing#middleware

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants