@@ -19,6 +19,7 @@ import {
1919 nextTick ,
2020 reactive ,
2121 ref ,
22+ shallowRef ,
2223 useTemplateRef ,
2324 watchEffect ,
2425} from '@vue/runtime-dom'
@@ -208,8 +209,8 @@ describe('api: template ref', () => {
208209 const { render } = define ( {
209210 setup ( ) {
210211 return {
211- foo : fooEl ,
212- bar : barEl ,
212+ foo : shallowRef ( fooEl ) ,
213+ bar : shallowRef ( barEl ) ,
213214 }
214215 } ,
215216 render ( ) {
@@ -251,6 +252,7 @@ describe('api: template ref', () => {
251252 } )
252253 const { host } = render ( )
253254 expect ( state . refKey ) . toBe ( host . children [ 0 ] )
255+ expect ( 'Template ref "refKey" used on a non-ref value' ) . toHaveBeenWarned ( )
254256 } )
255257
256258 test ( 'multiple root refs' , ( ) => {
@@ -713,6 +715,26 @@ describe('api: template ref', () => {
713715 expect ( html ( ) ) . toBe ( '<div>changed</div><!--dynamic-component-->' )
714716 } )
715717
718+ test ( 'should not attempt to set when variable name is same as key' , ( ) => {
719+ let tRef : ShallowRef
720+ const key = 'refKey'
721+ define ( {
722+ setup ( ) {
723+ tRef = useTemplateRef ( '_' )
724+ return {
725+ [ key ] : tRef ,
726+ }
727+ } ,
728+ render ( ) {
729+ const n0 = template ( '<div></div>' ) ( ) as Element
730+ createTemplateRefSetter ( ) ( n0 , key )
731+ return n0
732+ } ,
733+ } ) . render ( )
734+ expect ( 'target is readonly' ) . not . toHaveBeenWarned ( )
735+ expect ( tRef ! . value ) . toBe ( null )
736+ } )
737+
716738 // TODO: can not reproduce in Vapor
717739 // // #2078
718740 // test('handling multiple merged refs', async () => {
0 commit comments