From ef4ae7dd815c9059c23a8556d44451a0d30f46d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E9=81=93=E8=BF=9C?= Date: Thu, 26 Mar 2020 21:29:45 +0800 Subject: [PATCH] fix(patch.js): fix functional component scope attribute update fix functional component update scope attribute when patch use same node fix #11171 --- src/core/vdom/patch.js | 3 +++ .../modules/vdom/patch/edge-cases.spec.js | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 2052df913b3..44afc8c4b15 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -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) diff --git a/test/unit/modules/vdom/patch/edge-cases.spec.js b/test/unit/modules/vdom/patch/edge-cases.spec.js index a7f7ba38932..95296b7120c 100644 --- a/test/unit/modules/vdom/patch/edge-cases.spec.js +++ b/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 @@ -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) + }) })