fix(nuxt): give priority to later middleware when deduping (#23552)

This commit is contained in:
Daniel Roe 2023-10-12 23:21:02 +01:00 committed by GitHub
parent 20853a89ac
commit 458acbb8e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 8 deletions

View File

@ -152,7 +152,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
}
// Normalize and de-duplicate plugins and middleware
app.middleware = uniqueBy(await resolvePaths(app.middleware, 'path'), 'name')
app.middleware = uniqueBy(await resolvePaths([...app.middleware].reverse(), 'path'), 'name').reverse()
app.plugins = uniqueBy(await resolvePaths(app.plugins, 'src'), 'src')
// Resolve app.config

View File

@ -141,9 +141,9 @@ describe('resolveApp', () => {
// TODO: fix this
expect(fixtureMiddleware).toMatchInlineSnapshot(`
[
"<rootDir>/layer1/middleware/global.global.ts",
"<rootDir>/layer1/middleware/named-from-layer.ts",
"<rootDir>/layer1/middleware/named-override.ts",
"<rootDir>/layer2/middleware/global.global.ts",
"<rootDir>/layer2/middleware/named-from-layer.ts",
"<rootDir>/middleware/named-override.ts",
"<rootDir>/middleware/named.ts",
]
`)

View File

@ -1019,8 +1019,7 @@ describe('extends support', () => {
expect(html).toContain('Middleware | foo: Injected by extended middleware from foo')
})
// theme is added after layers
it('extends foo/middleware/override over bar/middleware/override', async () => {
it('extends bar/middleware/override over foo/middleware/override', async () => {
const html = await $fetch('/override')
expect(html).toContain('Middleware | override: Injected by extended middleware from bar')
})

View File

@ -1,3 +1,3 @@
export default defineNuxtRouteMiddleware((to) => {
to.meta.override = 'This middleware should be overridden by bar'
to.meta.override = 'Injected by extended middleware from bar'
})

View File

@ -1,3 +1,3 @@
export default defineNuxtRouteMiddleware((to) => {
to.meta.override = 'Injected by extended middleware from bar'
to.meta.override = 'This middleware should be overriden by bar'
})