@@ -19,38 +19,39 @@ export default defineComponent({
1919} )
2020
2121export function createClientOnly ( component ) {
22- const { setup, render : _render , template : _template } = component
23- if ( _render ) {
22+ const clone = { ...component }
23+
24+ if ( clone . render ) {
2425 // override the component render (non script setup component)
25- component . render = ( ctx , ...args ) => {
26+ clone . render = ( ctx , ...args ) => {
2627 return ctx . mounted$
27- ? h ( Fragment , null , [ h ( _render ( ctx , ... args ) , ctx . $attrs ?? ctx . _ . attrs ) ] )
28+ ? h ( Fragment , ctx . $attrs ?? ctx . _ . attrs , component . render ( ctx , ... args ) )
2829 : h ( 'div' , ctx . $attrs ?? ctx . _ . attrs )
2930 }
30- } else if ( _template ) {
31+ } else if ( clone . template ) {
3132 // handle runtime-compiler template
32- component . template = `
33- <template v-if="mounted$">${ _template } </template>
33+ clone . template = `
34+ <template v-if="mounted$">${ component . template } </template>
3435 <template v-else><div></div></template>
3536 `
3637 }
37- return defineComponent ( {
38- ...component ,
39- setup ( props , ctx ) {
40- const mounted$ = ref ( false )
41- onMounted ( ( ) => { mounted$ . value = true } )
4238
43- return Promise . resolve ( setup ?. ( props , ctx ) || { } )
44- . then ( ( setupState ) => {
45- return typeof setupState !== 'function'
46- ? { ...setupState , mounted$ }
47- : ( ...args ) => {
48- return mounted$ . value
39+ clone . setup = ( props , ctx ) => {
40+ const mounted$ = ref ( false )
41+ onMounted ( ( ) => { mounted$ . value = true } )
42+
43+ return Promise . resolve ( component . setup ?. ( props , ctx ) || { } )
44+ . then ( ( setupState ) => {
45+ return typeof setupState !== 'function'
46+ ? { ...setupState , mounted$ }
47+ : ( ...args ) => {
48+ return mounted$ . value
4949 // use Fragment to avoid oldChildren is null issue
50- ? h ( Fragment , null , [ h ( setupState ( ...args ) , ctx . attrs ) ] )
51- : h ( 'div' , ctx . attrs )
52- }
53- } )
54- }
55- } )
50+ ? h ( Fragment , ctx . attrs , setupState ( ...args ) )
51+ : h ( 'div' , ctx . attrs )
52+ }
53+ } )
54+ }
55+
56+ return clone
5657}
0 commit comments