nuxt-modules / nuxt-modules/ionic

Nuxt middleware & page setup does not execute in the expected order when refreshing page

Open
#564 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
457
Forks
53
Avg merge
7h 32m
Merged PRs (30d)
21

Description

🐛 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:
    image
  • (Nuxt + Nuxt/ionic) App setup gets run first but everything else in the correct order:
    image
  • (Nuxt + Nuxtjs/i18n) works as expected:
    image
  • (Nuxt + Nuxt/ionic + Nuxtjs/i18n) every page setup is run before middleware
    image

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

  1. Global middleware
  2. Page middleware
  3. App setup function
  4. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproduction and compare the Nuxt-only, Ionic, i18n, and Ionic-plus-i18n configurations. Inspect the nuxt.config router integration setting mentioned in the issue and reproduce the refresh behavior. Done means the combined setup preserves the expected order: global middleware, page middleware, app setup, then page setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
frontend, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.