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

fix(nuxt): don't generate separate chunk for stubs #26291

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
13 changes: 10 additions & 3 deletions packages/nuxt/src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
try {
extractedMeta[key] = JSON.parse(runInNewContext(`JSON.stringify(${valueString})`, {}))
} catch {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not JSON-serializable (reading \`${absolutePath}\`).`)

Check warning on line 200 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand All @@ -210,7 +210,7 @@
continue
}
if (element.type !== 'Literal' || typeof element.value !== 'string') {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not an array of string literals (reading \`${absolutePath}\`).`)

Check warning on line 213 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand All @@ -221,7 +221,7 @@
}

if (property.value.type !== 'Literal' || typeof property.value.value !== 'string') {
console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not a string literal or array of string literals (reading \`${absolutePath}\`).`)

Check warning on line 224 in packages/nuxt/src/pages/utils.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
dynamicProperties.add(key)
continue
}
Expand Down Expand Up @@ -444,9 +444,16 @@
}

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}`,
Expand All @@ -456,8 +463,8 @@
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') {
Expand Down
2 changes: 2 additions & 0 deletions packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export type NuxtPage = {
* @default 'all'
*/
mode?: 'client' | 'server' | 'all'
/** @internal */
_sync?: boolean
}

export type NuxtMiddleware = {
Expand Down