11import { createElementBlock , createElementVNode , defineComponent , h , mergeProps , onMounted , ref } from 'vue'
2+ import type { ComponentOptions } from 'vue'
23
34export default defineComponent ( {
45 name : 'ClientOnly' ,
@@ -8,7 +9,7 @@ export default defineComponent({
89 setup ( _ , { slots, attrs } ) {
910 const mounted = ref ( false )
1011 onMounted ( ( ) => { mounted . value = true } )
11- return ( props ) => {
12+ return ( props : any ) => {
1213 if ( mounted . value ) { return slots . default ?.( ) }
1314 const slot = slots . fallback || slots . placeholder
1415 if ( slot ) { return slot ( ) }
@@ -21,7 +22,7 @@ export default defineComponent({
2122
2223const cache = new WeakMap ( )
2324
24- export function createClientOnly ( component ) {
25+ export function createClientOnly < T extends ComponentOptions > ( component : T ) {
2526 if ( cache . has ( component ) ) {
2627 return cache . get ( component )
2728 }
@@ -30,9 +31,9 @@ export function createClientOnly (component) {
3031
3132 if ( clone . render ) {
3233 // override the component render (non script setup component)
33- clone . render = ( ctx , ...args ) => {
34+ clone . render = ( ctx : any , ...args : any [ ] ) => {
3435 if ( ctx . mounted$ ) {
35- const res = component . render ( ctx , ...args )
36+ const res = component . render ! ( ctx , ...args )
3637 return ( res . children === null || typeof res . children === 'string' )
3738 ? createElementVNode ( res . type , res . props , res . children , res . patchFlag , res . dynamicProps , res . shapeFlag )
3839 : h ( res )
@@ -56,7 +57,7 @@ export function createClientOnly (component) {
5657 . then ( ( setupState ) => {
5758 return typeof setupState !== 'function'
5859 ? { ...setupState , mounted$ }
59- : ( ...args ) => {
60+ : ( ...args : any [ ] ) => {
6061 if ( mounted$ . value ) {
6162 const res = setupState ( ...args )
6263 return ( res . children === null || typeof res . children === 'string' )
0 commit comments