fix(nuxt): don't render unknown components with placeholder (#18494)

This commit is contained in:
Daniel Roe 2023-01-25 02:30:59 -08:00 committed by GitHub
parent 3ec108493d
commit fdb31f418f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -133,12 +133,14 @@ function findComponent (components: Component[], name: string, mode: LoaderOptio
const component = components.find(component => id === component.pascalName && ['all', mode, undefined].includes(component.mode))
if (component) { return component }
const otherModeComponent = components.find(component => id === component.pascalName)
// Render client-only components on the server with <ServerPlaceholder> (a simple div)
if (mode === 'server' && !component) {
if (mode === 'server' && otherModeComponent) {
return components.find(c => c.pascalName === 'ServerPlaceholder')
}
// Return the other-mode component in all other cases - we'll handle createClientOnly
// and createServerComponent above
return components.find(component => id === component.pascalName)
return otherModeComponent
}

View File

@ -16,6 +16,7 @@
</NuxtLink>
<NestedSugarCounter :multiplier="2" />
<CustomComponent />
<Spin>Test</Spin>
<component :is="`test${'-'.toString()}global`" />
<component :is="`with${'-'.toString()}suffix`" />
<ClientWrapped ref="clientRef" style="color: red;" class="client-only" />

13
test/fixtures/basic/plugins/register.ts vendored Normal file
View File

@ -0,0 +1,13 @@
import { defineComponent, h } from 'vue'
const Spin = defineComponent({
setup (props, { slots }) {
return () => {
return h('div', slots.default?.())
}
}
})
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('Spin', Spin)
})