2023-03-20 21:47:06 +00:00
|
|
|
import type { defineAsyncComponent } from 'vue'
|
2023-04-07 16:02:47 +00:00
|
|
|
import { createVNode, defineComponent } from 'vue'
|
2022-11-24 12:24:14 +00:00
|
|
|
|
2023-10-30 21:05:02 +00:00
|
|
|
import { createError } from '../composables/error'
|
|
|
|
|
2023-04-14 12:53:21 +00:00
|
|
|
// @ts-expect-error virtual file
|
2022-11-24 12:24:14 +00:00
|
|
|
import * as islandComponents from '#build/components.islands.mjs'
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
context: {
|
|
|
|
type: Object as () => { name: string, props?: Record<string, any> },
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2023-03-20 21:47:06 +00:00
|
|
|
setup (props) {
|
|
|
|
const component = islandComponents[props.context.name] as ReturnType<typeof defineAsyncComponent>
|
2022-11-24 12:24:14 +00:00
|
|
|
|
|
|
|
if (!component) {
|
|
|
|
throw createError({
|
|
|
|
statusCode: 404,
|
2023-08-02 10:17:27 +00:00
|
|
|
statusMessage: `Island component not found: ${props.context.name}`
|
2022-11-24 12:24:14 +00:00
|
|
|
})
|
|
|
|
}
|
2023-05-15 22:43:53 +00:00
|
|
|
|
|
|
|
return () => createVNode(component || 'span', { ...props.context.props, 'nuxt-ssr-component-uid': '' })
|
2022-11-24 12:24:14 +00:00
|
|
|
}
|
|
|
|
})
|