File tree 2 files changed +28
-11
lines changed
2 files changed +28
-11
lines changed Original file line number Diff line number Diff line change 5
5
render ,
6
6
nextTick ,
7
7
Ref ,
8
- defineComponent
8
+ defineComponent ,
9
+ reactive
9
10
} from '@vue/runtime-test'
10
11
11
12
// reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
@@ -200,4 +201,22 @@ describe('api: template refs', () => {
200
201
201
202
expect ( spy ) . toHaveBeenCalledWith ( 'div' )
202
203
} )
204
+
205
+ it ( 'should work with direct reactive property' , ( ) => {
206
+ const root = nodeOps . createElement ( 'div' )
207
+ const state = reactive ( {
208
+ refKey : null
209
+ } )
210
+
211
+ const Comp = {
212
+ setup ( ) {
213
+ return state
214
+ } ,
215
+ render ( ) {
216
+ return h ( 'div' , { ref : 'refKey' } )
217
+ }
218
+ }
219
+ render ( h ( Comp ) , root )
220
+ expect ( state . refKey ) . toBe ( root . children [ 0 ] )
221
+ } )
203
222
} )
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ import {
32
32
isFunction ,
33
33
PatchFlags ,
34
34
ShapeFlags ,
35
- NOOP
35
+ NOOP ,
36
+ hasOwn
36
37
} from '@vue/shared'
37
38
import {
38
39
queueJob ,
@@ -45,7 +46,6 @@ import {
45
46
stop ,
46
47
ReactiveEffectOptions ,
47
48
isRef ,
48
- toRaw ,
49
49
DebuggerEvent
50
50
} from '@vue/reactivity'
51
51
import { resolveProps } from './componentProps'
@@ -1859,27 +1859,25 @@ function baseCreateRenderer(
1859
1859
}
1860
1860
const oldRef = oldRawRef && oldRawRef [ 1 ]
1861
1861
const refs = owner . refs === EMPTY_OBJ ? ( owner . refs = { } ) : owner . refs
1862
- const renderContext = toRaw ( owner . renderContext )
1862
+ const renderContext = owner . renderContext
1863
1863
1864
1864
// unset old ref
1865
1865
if ( oldRef != null && oldRef !== ref ) {
1866
1866
if ( isString ( oldRef ) ) {
1867
1867
refs [ oldRef ] = null
1868
- const oldSetupRef = renderContext [ oldRef ]
1869
- if ( isRef ( oldSetupRef ) ) {
1870
- oldSetupRef . value = null
1868
+ if ( hasOwn ( renderContext , oldRef ) ) {
1869
+ renderContext [ oldRef ] = null
1871
1870
}
1872
1871
} else if ( isRef ( oldRef ) ) {
1873
1872
oldRef . value = null
1874
1873
}
1875
1874
}
1876
1875
1877
1876
if ( isString ( ref ) ) {
1878
- const setupRef = renderContext [ ref ]
1879
- if ( isRef ( setupRef ) ) {
1880
- setupRef . value = value
1881
- }
1882
1877
refs [ ref ] = value
1878
+ if ( hasOwn ( renderContext , ref ) ) {
1879
+ renderContext [ ref ] = value
1880
+ }
1883
1881
} else if ( isRef ( ref ) ) {
1884
1882
ref . value = value
1885
1883
} else if ( isFunction ( ref ) ) {
You can’t perform that action at this time.
0 commit comments