Skip to content

Commit e0b26c4

Browse files
authored
fix: fix parent of multi-nested HOC $el not updating (#12757)
fix #12589
1 parent 46ca7bc commit e0b26c4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/core/instance/lifecycle.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ export function lifecycleMixin(Vue: typeof Component) {
8383
vm.$el.__vue__ = vm
8484
}
8585
// if parent is an HOC, update its $el as well
86-
if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
87-
vm.$parent.$el = vm.$el
86+
let wrapper: Component | undefined = vm
87+
while (
88+
wrapper &&
89+
wrapper.$vnode &&
90+
wrapper.$parent &&
91+
wrapper.$vnode === wrapper.$parent._vnode
92+
) {
93+
wrapper.$parent.$el = wrapper.$el
94+
wrapper = wrapper.$parent
8895
}
8996
// updated hook is called by the scheduler to ensure that children are
9097
// updated in a parent's updated hook.

test/unit/modules/vdom/patch/edge-cases.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,15 @@ describe('vdom patch: edge cases', () => {
257257

258258
expect(vm.$refs.foo.$refs.bar.$el.tagName).toBe('DIV')
259259
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
260+
expect(vm.$el.tagName).toBe('DIV')
261+
expect(vm.$el.className).toBe(`hello`)
260262

261263
vm.$refs.foo.$refs.bar.ok = false
262264
waitForUpdate(() => {
263265
expect(vm.$refs.foo.$refs.bar.$el.tagName).toBe('SPAN')
264266
expect(vm.$refs.foo.$refs.bar.$el.className).toBe(`hello`)
267+
expect(vm.$el.tagName).toBe('SPAN')
268+
expect(vm.$el.className).toBe(`hello`)
265269
}).then(done)
266270
})
267271

0 commit comments

Comments
 (0)