fix(nuxt): don't warn when injecting client-only components (#26341)

This commit is contained in:
Daniel Roe 2024-03-18 14:41:01 +00:00 committed by GitHub
parent 2c0fc3a15e
commit 90591e3a3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -165,6 +165,8 @@ export default defineNuxtModule<ComponentsOptions>({
}
})
const serverPlaceholderPath = resolve(distDir, 'app/components/server-placeholder')
// Scan components and add to plugin
nuxt.hook('app:templates', async (app) => {
const newComponents = await scanComponents(componentDirs, nuxt.options.srcDir!)
@ -176,11 +178,11 @@ export default defineNuxtModule<ComponentsOptions>({
...component,
_raw: true,
mode: 'server',
filePath: resolve(distDir, 'app/components/server-placeholder'),
filePath: serverPlaceholderPath,
chunkName: 'components/' + component.kebabName
})
}
if (component.mode === 'server' && !nuxt.options.ssr) {
if (component.mode === 'server' && !nuxt.options.ssr && !newComponents.some(other => other.pascalName === component.pascalName && other.mode === 'client')) {
logger.warn(`Using server components with \`ssr: false\` is not supported with auto-detected component islands. If you need to use server component \`${component.pascalName}\`, set \`experimental.componentIslands\` to \`true\`.`)
}
}

View File

@ -378,7 +378,7 @@ export const nuxtConfigTemplate: NuxtTemplate = {
headers: undefined
}
const shouldEnableComponentIslands = ctx.nuxt.options.experimental.componentIslands && (
ctx.nuxt.options.dev || ctx.nuxt.options.experimental.componentIslands !== 'auto' || ctx.app.pages?.some(p => p.mode === 'server') || ctx.app.components?.some(c => c.mode === 'server')
ctx.nuxt.options.dev || ctx.nuxt.options.experimental.componentIslands !== 'auto' || ctx.app.pages?.some(p => p.mode === 'server') || ctx.app.components?.some(c => c.mode === 'server' && !ctx.app.components.some(other => other.pascalName === c.pascalName && other.mode === 'client'))
)
return [
...Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`),