@@ -30,7 +30,8 @@ import {
30
30
isFunction ,
31
31
PatchFlags ,
32
32
ShapeFlags ,
33
- NOOP
33
+ NOOP ,
34
+ isArray
34
35
} from '@vue/shared'
35
36
import {
36
37
queueJob ,
@@ -1793,11 +1794,19 @@ function baseCreateRenderer<
1793
1794
}
1794
1795
1795
1796
const setRef = (
1796
- ref : string | Function | Ref ,
1797
- oldRef : string | Function | Ref | null ,
1797
+ ref : string | Function | Ref | [ ComponentPublicInstance , string ] ,
1798
+ oldRef : string | Function | Ref | [ ComponentPublicInstance , string ] | null ,
1798
1799
parent : ComponentInternalInstance ,
1799
1800
value : HostNode | ComponentPublicInstance | null
1800
1801
) => {
1802
+ if ( isArray ( ref ) ) {
1803
+ // template string refs are compiled into tuples like [ctx, key] to
1804
+ // ensure refs inside slots are set on the correct owner instance.
1805
+ const [ { $ : owner } , key ] = ref
1806
+ setRef ( key , oldRef && ( oldRef as any [ ] ) [ 1 ] , owner , value )
1807
+ return
1808
+ }
1809
+
1801
1810
const refs = parent . refs === EMPTY_OBJ ? ( parent . refs = { } ) : parent . refs
1802
1811
const renderContext = toRaw ( parent . renderContext )
1803
1812
@@ -1823,7 +1832,7 @@ function baseCreateRenderer<
1823
1832
} else if ( isRef ( ref ) ) {
1824
1833
ref . value = value
1825
1834
} else if ( isFunction ( ref ) ) {
1826
- callWithErrorHandling ( ref , parent , ErrorCodes . FUNCTION_REF , [ value , refs ] )
1835
+ callWithErrorHandling ( ref , parent , ErrorCodes . FUNCTION_REF , [ value ] )
1827
1836
} else if ( __DEV__ ) {
1828
1837
warn ( 'Invalid template ref type:' , value , `(${ typeof value } )` )
1829
1838
}
0 commit comments