fix(nuxt): skip middleware for islands components (#20924)

This commit is contained in:
Julien Huang 2023-05-21 00:26:29 +02:00 committed by GitHub
parent b88aab049f
commit 2d680455ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 47 deletions

View File

@ -235,6 +235,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
}
nuxtApp._processingMiddleware = true
if (process.client || !nuxtApp.ssrContext?.islandContext) {
const middlewareEntries = new Set<RouteGuard>([...globalMiddleware, ...nuxtApp._middleware.global])
for (const middleware of middlewareEntries) {
@ -251,6 +252,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
}
if (result || result === false) { return result }
}
}
})
router.afterEach(() => { delete nuxtApp._processingMiddleware })

View File

@ -135,6 +135,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
}
nuxtApp._processingMiddleware = true
if (process.client || !nuxtApp.ssrContext?.islandContext) {
type MiddlewareDef = string | RouteMiddleware
const middlewareEntries = new Set<MiddlewareDef>([...globalMiddleware, ...nuxtApp._middleware.global])
for (const component of to.matched) {
@ -172,6 +173,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
}
if (result || result === false) { return result }
}
}
})
router.onError(() => { delete nuxtApp._processingMiddleware })

View File

@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.2k"')
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.4k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2283k"')