File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
test/unit/modules/vdom/patch Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -660,14 +660,18 @@ export function createPatchFunction (backend) {
660660 // component root element replaced.
661661 // update parent placeholder node element, recursively
662662 let ancestor = vnode . parent
663+ const patchable = isPatchable ( vnode )
663664 while ( ancestor ) {
665+ for ( let i = 0 ; i < cbs . destroy . length ; ++ i ) {
666+ cbs . destroy [ i ] ( ancestor )
667+ }
664668 ancestor . elm = vnode . elm
665- ancestor = ancestor . parent
666- }
667- if ( isPatchable ( vnode ) ) {
668- for ( let i = 0 ; i < cbs . create . length ; ++ i ) {
669- cbs . create [ i ] ( emptyNode , vnode . parent )
669+ if ( patchable ) {
670+ for ( let i = 0 ; i < cbs . create . length ; ++ i ) {
671+ cbs . create [ i ] ( emptyNode , ancestor )
672+ }
670673 }
674+ ancestor = ancestor . parent
671675 }
672676 }
673677
Original file line number Diff line number Diff line change @@ -161,4 +161,32 @@ describe('vdom patch: edge cases', () => {
161161 expect ( vm . $el . children [ 0 ] . type ) . toBe ( 'password' )
162162 } ) . then ( done )
163163 } )
164+
165+ it ( 'should properly patch nested HOC when root element is replaced' , done => {
166+ const vm = new Vue ( {
167+ template : `<foo class="hello" ref="foo" />` ,
168+ components : {
169+ foo : {
170+ template : `<bar ref="bar" />` ,
171+ components : {
172+ bar : {
173+ template : `<div v-if="ok"></div><span v-else></span>` ,
174+ data ( ) {
175+ return { ok : true }
176+ }
177+ }
178+ }
179+ }
180+ }
181+ } ) . $mount ( )
182+
183+ expect ( vm . $refs . foo . $refs . bar . $el . tagName ) . toBe ( 'DIV' )
184+ expect ( vm . $refs . foo . $refs . bar . $el . className ) . toBe ( `hello` )
185+
186+ vm . $refs . foo . $refs . bar . ok = false
187+ waitForUpdate ( ( ) => {
188+ expect ( vm . $refs . foo . $refs . bar . $el . tagName ) . toBe ( 'SPAN' )
189+ expect ( vm . $refs . foo . $refs . bar . $el . className ) . toBe ( `hello` )
190+ } ) . then ( done )
191+ } )
164192} )
You can’t perform that action at this time.
0 commit comments