diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index dcdaf239eef..4939811562f 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -670,6 +670,16 @@ export function createPatchFunction (backend) { for (let i = 0; i < cbs.create.length; ++i) { cbs.create[i](emptyNode, ancestor) } + // #6513 + // invoke insert hooks that may have been merged by create hooks. + // e.g. for directives that uses the "inserted" hook. + const insert = ancestor.data.hook.insert + if (insert.merged) { + // start at index 1 to avoid re-invoking component mounted hook + for (let i = 1; i < insert.fns.length; i++) { + insert.fns[i]() + } + } } ancestor = ancestor.parent } diff --git a/test/unit/features/options/directives.spec.js b/test/unit/features/options/directives.spec.js index 44362250fe2..f15dd77f8e6 100644 --- a/test/unit/features/options/directives.spec.js +++ b/test/unit/features/options/directives.spec.js @@ -227,4 +227,42 @@ describe('Options directives', () => { }).$mount() expect('Failed to resolve directive: test').toHaveBeenWarned() }) + + // #6513 + it('should invoke unbind & inserted on inner component root element change', done => { + const dir = { + bind: jasmine.createSpy('bind'), + inserted: jasmine.createSpy('inserted'), + unbind: jasmine.createSpy('unbind') + } + + const Child = { + template: `
`, + data: () => ({ ok: true }) + } + + const vm = new Vue({ + template: `