Nuxt middleware & page setup does not execute in the expected order when refreshing page
đ The bug
I was using middleware to fetch user configuration data before navigating to pages, when I realized that the page setup was run before the middleware. Through some trial and error I figured out that removing Nuxt/ionic fixed the issue, but I also found out that adding the Nuxtjs/i18n module worsened the issue.
So I created a project tracking the following:
- Global middleware
- Page middleware
- App setup function
- Page setup function
And I got these results:
- (Nuxt alone) works as expected:
- (Nuxt + Nuxt/ionic) App setup gets run first but everything else in the correct order:
- (Nuxt + Nuxtjs/i18n) works as expected:
- (Nuxt + Nuxt/ionic + Nuxtjs/i18n) every page setup is run before middleware
I'm still pretty new to Nuxt & Ionic so I might be completely missing some critical information, but the Nuxt/ionic documentation gives the impression that middleware should just work with no caveats.
đ ī¸ To reproduce
https://stackblitz.com/edit/hui123
đ Expected behaviour
For the execution order to match the basic Nuxt project when refreshing the page, and to also work with the i18n nuxt module
- Global middleware
- Page middleware
- App setup function
- Page setup function
âšī¸ Additional context
Reproductions used to get the different results: Nuxt middleware order (Nuxt only) Nuxt middleware order (Ionic) Nuxt middleware order (i18n) Nuxt middleware order (Ionic + i18n)
It might be related to the ionic router integration, because if I disable it in nuxt.config the execution order goes back to normal.
I was hoping the needs reproduction label would disappear after a while, but that doesn't seem to be the case.
That must mean that I'm doing something wrong even though I thought I had provided reproductions. Can anyone point me in the right direction on how to fix my issue, so the needs reproduction label disappears?
I'm afraid that is the fault of the bot, not you!
Do you think this is something that can / should be fixed @danielroe ? I can try to pick this up.
So I used the reproduction URL provided and updated both the i18n and the Nuxt ionic package to the latest 0.18.0 and updating i18n didn't make a difference but updating nuxt ionic does seem to fix this issue! See here.
I imagine App setup always running first is not a bug but intended behavior as we "inject" nuxt's middleware behavior between pages so it will never be a 1 to 1.
thank you for diving in â¤ī¸