mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): give priority to later middleware when deduping (#23552)
This commit is contained in:
parent
20853a89ac
commit
458acbb8e1
@ -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
|
||||
|
@ -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",
|
||||
]
|
||||
`)
|
||||
|
@ -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')
|
||||
})
|
||||
|
@ -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'
|
||||
})
|
||||
|
2
test/fixtures/basic/extends/node_modules/foo/middleware/override.ts
generated
vendored
2
test/fixtures/basic/extends/node_modules/foo/middleware/override.ts
generated
vendored
@ -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'
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user