Skip to content

Commit

Permalink
fix(nuxt): don't render unknown components with placeholder (#18494)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 25, 2023
1 parent 3ec1084 commit fdb31f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/components/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions test/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/basic/plugins/register.ts
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit fdb31f4

Please sign in to comment.