Skip to content

Commit

Permalink
fix(nuxt): don't warn when injecting client-only components (#26341)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 18, 2024
1 parent 2c0fc3a commit 90591e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -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\`.`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`),
Expand Down

0 comments on commit 90591e3

Please sign in to comment.