From 814859d769babc5893d0c6f95417dd71c1aac90d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 15 Mar 2024 17:07:38 -0700 Subject: [PATCH] fix(nuxt): don't generate separate chunk for stubs (#26291) --- packages/nuxt/src/pages/module.ts | 1 + packages/nuxt/src/pages/utils.ts | 13 ++++++++++--- packages/schema/src/types/hooks.ts | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 9eb1eefaa2..f03c6279c3 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -364,6 +364,7 @@ export default defineNuxtModule({ const rule = nitro.options.routeRules[path] if (!rule.redirect) { continue } routes.push({ + _sync: true, path: path.replace(/\/[^/]*\*\*/, '/:pathMatch(.*)'), file: resolve(runtimeDir, 'component-stub') }) diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index af3386e70e..28ece519e6 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -444,9 +444,16 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set = } const file = normalize(page.file) - const metaImportName = genSafeVariableName(filename(file) + hash(file)) + 'Meta' + const pageImportName = genSafeVariableName(filename(file) + hash(file)) + const metaImportName = pageImportName + 'Meta' metaImports.add(genImport(`${file}?macro=true`, [{ name: 'default', as: metaImportName }])) + if (page._sync) { + metaImports.add(genImport(file, [{ name: 'default', as: pageImportName }])) + } + + const pageImport = page._sync && page.mode !== 'client' ? pageImportName : genDynamicImport(file, { interopDefault: true }) + const metaRoute: NormalizedRoute = { name: `${metaImportName}?.name ?? ${route.name}`, path: `${metaImportName}?.path ?? ${route.path}`, @@ -456,8 +463,8 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set = component: page.mode === 'server' ? `() => createIslandPage(${route.name})` : page.mode === 'client' - ? `() => createClientPage(${genDynamicImport(file, { interopDefault: true })})` - : genDynamicImport(file, { interopDefault: true }) + ? `() => createClientPage(${pageImport})` + : pageImport } if (page.mode === 'server') { diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 6a33051266..1c4fde5fad 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -44,6 +44,8 @@ export type NuxtPage = { * @default 'all' */ mode?: 'client' | 'server' | 'all' + /** @internal */ + _sync?: boolean } export type NuxtMiddleware = {