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

Global middlewares ignore alphabetical order when using Nuxt Layers #25891

Open
oemer-aran opened this issue Feb 21, 2024 · 1 comment · May be fixed by #25906
Open

Global middlewares ignore alphabetical order when using Nuxt Layers #25891

oemer-aran opened this issue Feb 21, 2024 · 1 comment · May be fixed by #25906

Comments

@oemer-aran
Copy link

Environment

  • Operating System: Darwin
  • Node Version: v20.7.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.9.1
  • Nitro Version: 2.8.0
  • Package Manager: yarn@3.5.1
  • Builder: -
  • User Config: extends, alias, dir, typescript, app, components, imports
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-zx3fux

Describe the bug

Using global middlewares with Nuxt Layers will not retain the alphabetical order based on the file names.

In my repodruction my nuxt-app project extends base-layer.

Global middlwares in nuxt-app:

  • 00.main.global.ts

Global middlwares in base-layer:

  • 01.base.global.ts

Expcted order:

  • 00.main.global.ts
  • 01.base.global.ts

Actual order:

  • 01.base.global.ts
  • 00.main.global.ts

Check logs in the reproduction.

Currently I fixed the issue by using plugins to register the middlewares in the right order:
Base Plugin:

// base-layer/plugins/00.global-middleware-fix.ts
export default defineNuxtPlugin(() => {
  globalBaseMiddlewares.forEach((middleware, index) => addRouteMiddleware(`00-${index}`, middleware, { global: true }))
})

Main Plugin:

// plugins/00.global-middleware-fix.ts
export default defineNuxtPlugin(() => {
  globalMainMiddlewares.forEach((middleware, index) => addRouteMiddleware(`00-${index}`, middleware, { global: true }))
})

Additional context

Related stackoverflow post: https://stackoverflow.com/questions/77826748/order-of-middlewares-in-nuxt3-layers

Logs

No response

Copy link

stackblitz bot commented Feb 21, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@manniL manniL added the layers label Feb 21, 2024
markthree added a commit to markthree/nuxt that referenced this issue Feb 22, 2024
@markthree markthree linked a pull request Feb 22, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants