File tree 3 files changed +18
-1
lines changed
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export default {
17
17
}
18
18
}
19
19
20
- function registerRef ( vnode : VNodeWithData , isRemoval : ?boolean ) {
20
+ export function registerRef ( vnode : VNodeWithData , isRemoval : ?boolean ) {
21
21
const key = vnode . data . ref
22
22
if ( ! key ) return
23
23
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import config from '../config'
11
11
import VNode from './vnode'
12
12
import { isPrimitive , _toString , warn } from '../util/index'
13
13
import { activeInstance } from '../instance/lifecycle'
14
+ import { registerRef } from './modules/ref'
14
15
15
16
const emptyData = { }
16
17
const emptyNode = new VNode ( '' , emptyData , [ ] )
@@ -156,6 +157,10 @@ export function createPatchFunction (backend) {
156
157
invokeCreateHooks ( vnode , insertedVnodeQueue )
157
158
setScope ( vnode )
158
159
} else {
160
+ // empty component root.
161
+ // skip all element-related modules except for ref (#3455)
162
+ registerRef ( vnode )
163
+ // make sure to invoke the insert hook
159
164
insertedVnodeQueue . push ( vnode )
160
165
}
161
166
}
Original file line number Diff line number Diff line change @@ -145,4 +145,16 @@ describe('ref', () => {
145
145
expect ( vm . $refs . list . every ( ( comp , i ) => comp . $el . textContent === String ( i + 1 ) ) ) . toBe ( true )
146
146
}
147
147
} )
148
+
149
+ it ( 'should register on component with empty roots' , ( ) => {
150
+ const vm = new Vue ( {
151
+ template : '<child ref="test"></child>' ,
152
+ components : {
153
+ child : {
154
+ template : '<div v-if="false"></div>'
155
+ }
156
+ }
157
+ } ) . $mount ( )
158
+ expect ( vm . $refs . test ) . toBe ( vm . $children [ 0 ] )
159
+ } )
148
160
} )
You can’t perform that action at this time.
0 commit comments