Skip to content

Commit

Permalink
fix(patch.js): fix functional component scope attribute update
Browse files Browse the repository at this point in the history
fix functional component update scope attribute when patch use same node

fix vuejs#11171
  • Loading branch information
唐道远 authored and 唐道远 committed Mar 26, 2020
1 parent a59e05c commit ef4ae7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/vdom/patch.js
Expand Up @@ -547,6 +547,9 @@ export function createPatchFunction (backend) {

const oldCh = oldVnode.children
const ch = vnode.children
if (isDef(vnode.fnScopeId)) {
setScope(vnode)
}
if (isDef(data) && isPatchable(vnode)) {
for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)
if (isDef(i = data.hook) && isDef(i = i.update)) i(oldVnode, vnode)
Expand Down
22 changes: 22 additions & 0 deletions test/unit/modules/vdom/patch/edge-cases.spec.js
@@ -1,4 +1,5 @@
import Vue from 'vue'
import { patch } from 'web/runtime/patch'

describe('vdom patch: edge cases', () => {
// exposed by #3406
Expand Down Expand Up @@ -432,4 +433,25 @@ describe('vdom patch: edge cases', () => {
expect(vm.$el.textContent).not.toMatch('Infinity')
}).then(done)
})

// #11171
it("should replace functional element scope attribute", () => {
const vm = new Vue({
components: {
foo: {
functional: true,
_scopeId: "foo",
render (h) {
return h('div')
}
}
}
})
const h = vm.$createElement
const vnode = h('foo')
const oldVnode = h("div")
patch(null, oldVnode)
let elm = patch(oldVnode, vnode)
expect(elm.hasAttribute("foo")).toBe(true)
})
})

0 comments on commit ef4ae7d

Please sign in to comment.