@@ -34,26 +34,32 @@ export type setRefFn = (
3434
3535export function createTemplateRefSetter ( ) : setRefFn {
3636 const instance = currentInstance as VaporComponentInstance
37- return ( ... args ) => setRef ( instance , ... args )
37+ return ( el , ref , oldRef , refFor ) => setRef ( el , ref , oldRef , refFor , instance )
3838}
3939
4040/**
4141 * Function for handling a template ref
4242 */
4343export function setRef (
44- instance : VaporComponentInstance ,
4544 el : RefEl ,
4645 ref : NodeRef ,
4746 oldRef ?: NodeRef ,
4847 refFor = false ,
48+ instance ?: VaporComponentInstance ,
4949) : NodeRef | undefined {
50- if ( ! instance || instance . isUnmounted ) return
50+ const _isString = isString ( ref )
51+ if ( _isString && ( ! instance || instance . isUnmounted ) ) return
5152
52- const setupState : any = __DEV__ ? instance . setupState || { } : null
53+ const setupState : any = __DEV__
54+ ? ( instance && instance . setupState ) || { }
55+ : null
5356 const refValue = getRefValue ( el )
5457
55- const refs =
56- instance . refs === EMPTY_OBJ ? ( instance . refs = { } ) : instance . refs
58+ const refs = instance
59+ ? instance . refs === EMPTY_OBJ
60+ ? ( instance . refs = { } )
61+ : instance . refs
62+ : { }
5763
5864 // dynamic ref changed. unset old ref
5965 if ( oldRef != null && oldRef !== ref ) {
@@ -79,7 +85,6 @@ export function setRef(
7985 // TODO this gets called repeatedly in renderEffect when it's dynamic ref?
8086 onScopeDispose ( ( ) => invokeRefSetter ( ) )
8187 } else {
82- const _isString = isString ( ref )
8388 const _isRef = isRef ( ref )
8489 let existing : unknown
8590
0 commit comments