File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1057,6 +1057,54 @@ describe('interop: template ref', () => {
10571057 )
10581058 } )
10591059
1060+ test ( 'vapor app: useTemplateRef with vdom child + insertionState' , async ( ) => {
1061+ const { container } = await testTemplateRefInterop (
1062+ `<script vapor>
1063+ import { useTemplateRef } from 'vue'
1064+ const components = _components;
1065+ const elRef = useTemplateRef('el')
1066+ function click() {
1067+ elRef.value.change()
1068+ }
1069+ </script>
1070+ <template>
1071+ <div>
1072+ <button class="btn" @click="click"></button>
1073+ <components.VDOMChild ref="el"/>
1074+ </div>
1075+ </template>` ,
1076+ {
1077+ VDOMChild : {
1078+ code : `
1079+ <script setup>
1080+ import { ref } from 'vue'
1081+ const msg = ref('foo')
1082+ function change(){
1083+ msg.value = 'bar'
1084+ }
1085+ defineExpose({ change })
1086+ </script>
1087+ <template><div>{{msg}}</div></template>
1088+ ` ,
1089+ vapor : false ,
1090+ } ,
1091+ } ,
1092+ undefined ,
1093+ { vapor : true } ,
1094+ )
1095+
1096+ expect ( container . innerHTML ) . toBe (
1097+ `<div><button class="btn"></button><div>foo</div></div>` ,
1098+ )
1099+
1100+ const btn = container . querySelector ( '.btn' )
1101+ triggerEvent ( 'click' , btn ! )
1102+ await nextTick ( )
1103+ expect ( container . innerHTML ) . toBe (
1104+ `<div><button class="btn"></button><div>bar</div></div>` ,
1105+ )
1106+ } )
1107+
10601108 test ( 'vapor app: static ref with vdom child' , async ( ) => {
10611109 const { container } = await testTemplateRefInterop (
10621110 `<script vapor>
Original file line number Diff line number Diff line change @@ -421,6 +421,10 @@ function createVDOMComponent(
421421 } ,
422422 instance as any ,
423423 )
424+
425+ if ( isMounted && rawRef ) {
426+ vdomSetRef ( rawRef , null , null , vnode )
427+ }
424428 }
425429
426430 return frag
You can’t perform that action at this time.
0 commit comments