Skip to content

Commit

Permalink
fix: fix parent of multi-nested HOC $el not updating (#12757)
Browse files Browse the repository at this point in the history
fix #12589
  • Loading branch information
nooooooom authored Aug 23, 2022
1 parent 46ca7bc commit e0b26c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/instance/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ export function lifecycleMixin(Vue: typeof Component) {
vm.$el.__vue__ = vm
}
// if parent is an HOC, update its $el as well
if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
vm.$parent.$el = vm.$el
let wrapper: Component | undefined = vm
while (
wrapper &&
wrapper.$vnode &&
wrapper.$parent &&
wrapper.$vnode === wrapper.$parent._vnode
) {
wrapper.$parent.$el = wrapper.$el
wrapper = wrapper.$parent
}
// updated hook is called by the scheduler to ensure that children are
// updated in a parent's updated hook.
Expand Down
4 changes: 4 additions & 0 deletions test/unit/modules/vdom/patch/edge-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,15 @@ describe('vdom patch: edge cases', () => {

expect(vm.$refs.foo.$refs.bar.$el.tagName).toBe('DIV')
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
expect(vm.$el.tagName).toBe('DIV')
expect(vm.$el.className).toBe(`hello`)

vm.$refs.foo.$refs.bar.ok = false
waitForUpdate(() => {
expect(vm.$refs.foo.$refs.bar.$el.tagName).toBe('SPAN')
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
expect(vm.$el.tagName).toBe('SPAN')
expect(vm.$el.className).toBe(`hello`)
}).then(done)
})

Expand Down

0 comments on commit e0b26c4

Please sign in to comment.