File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
test/unit/modules/vdom/patch Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -878,8 +878,11 @@ export function createPatchFunction(backend) {
878878 const insert = ancestor . data . hook . insert
879879 if ( insert . merged ) {
880880 // start at index 1 to avoid re-invoking component mounted hook
881- for ( let i = 1 ; i < insert . fns . length ; i ++ ) {
882- insert . fns [ i ] ( )
881+ // clone insert hooks to avoid being mutated during iteration.
882+ // e.g. for customed directives under transition group.
883+ const cloned = insert . fns . slice ( 1 )
884+ for ( let i = 0 ; i < cloned . length ; i ++ ) {
885+ cloned [ i ] ( )
883886 }
884887 }
885888 } else {
Original file line number Diff line number Diff line change @@ -467,4 +467,42 @@ describe('vdom patch: edge cases', () => {
467467 vm . visible = false
468468 vm . $nextTick ( done )
469469 } )
470+
471+ it ( 'should call directive\'s inserted hook correctly when template root is changed' , done => {
472+ let insertCalled = false
473+ const vm = new Vue ( {
474+ data : {
475+ isOn : false
476+ } ,
477+ components : {
478+ 'v-switch' : {
479+ props : {
480+ on : Boolean
481+ } ,
482+ template : `
483+ <div v-if="on" key="on">On</div>
484+ <div v-else key="off">Off</div>`
485+ }
486+ } ,
487+ directives : {
488+ foo : {
489+ inserted ( ) {
490+ insertCalled = true
491+ }
492+ }
493+ } ,
494+ template : `
495+ <transition-group>
496+ <v-switch key="swicth" v-foo :on="isOn"/>
497+ </transition-group>
498+ `
499+ } ) . $mount ( )
500+
501+ vm . isOn = true
502+ insertCalled = false
503+ waitForUpdate ( ( ) => {
504+ expect ( vm . $el . textContent ) . toMatch ( 'On' )
505+ expect ( insertCalled ) . toBe ( true )
506+ } ) . then ( done )
507+ } )
470508} )
You can’t perform that action at this time.
0 commit comments