useTemplateRef returns ShallowRef instead of Ref #12731
Description
Vue version
v3.5.13
Link to minimal reproduction
Steps to reproduce
- Click on
Add to useTemplateRef
repeatedly and watch how the length of elements inside the component ref is desynced from the real count. - Now click on
Add to ref
and watch how the length of elements inside the component ref is same as the real count.
What is expected?
Current documentation suggests that useTemplateRef
is a drop-in replacement for the original component ref syntax (const refname = ref()
). Therefore their behaviors should be identical and useTemplateRef
should return a Ref
.
What is actually happening?
useTemplateRef
returns a ShallowRef
. This breaks reactivity when using a component ref on a looped element inside a v-for (in comparison to using the original component ref syntax const refname = ref()
)
System Info
Any additional comments?
Would suggest adding useTemplateShallowRef as a variant of useTemplateRef, which would then use the ShallowRef.