From 5340f1b87045e0d34a2f8de76adc2c77cd104ae2 Mon Sep 17 00:00:00 2001 From: Zhenfei You Date: Mon, 23 Oct 2017 20:47:54 +0800 Subject: [PATCH 1/3] fix: don't set ignoredElements' attributes to their default values (#6864) --- src/platforms/web/runtime/modules/attrs.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index 317316d8507..c6018ed3437 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -1,6 +1,7 @@ /* @flow */ import { isIE9, isEdge } from 'core/util/env' +import config from 'core/config' import { extend, @@ -59,6 +60,13 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } function setAttr (el: Element, key: string, value: any) { + // The attributes are not set to their default values + // for elements in the ignoredElements array + // eg. + if (config.ignoredElements.indexOf(el.tagName.toLowerCase()) > -1) { + el.setAttribute(key, value) + return + } if (isBooleanAttr(key)) { // set attribute for blank value // e.g. From 2cf684fdebd436a56876fb6f6297f651d1ec744b Mon Sep 17 00:00:00 2001 From: Zhenfei You Date: Mon, 30 Oct 2017 19:49:05 +0800 Subject: [PATCH 2/3] fix: better way to flag ignoredElements --- src/core/vdom/patch.js | 19 +++++++++++-------- src/core/vdom/vnode.js | 2 ++ src/platforms/web/runtime/modules/attrs.js | 9 ++++----- test/unit/features/global-api/config.spec.js | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index f06a1feb079..0062761f99e 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -118,17 +118,20 @@ export function createPatchFunction (backend) { if (data && data.pre) { inPre++ } + if ( + config.ignoredElements.length && + config.ignoredElements.some(ignore => { + return isRegExp(ignore) + ? ignore.test(tag) + : ignore === tag + }) + ) { + vnode.isIgnoredElement = true + } if ( !inPre && !vnode.ns && - !( - config.ignoredElements.length && - config.ignoredElements.some(ignore => { - return isRegExp(ignore) - ? ignore.test(tag) - : ignore === tag - }) - ) && + !vnode.isIgnoredElement && config.isUnknownElement(tag) ) { warn( diff --git a/src/core/vdom/vnode.js b/src/core/vdom/vnode.js index a34330de55b..e0527e9ab5b 100644 --- a/src/core/vdom/vnode.js +++ b/src/core/vdom/vnode.js @@ -23,6 +23,7 @@ export default class VNode { asyncFactory: Function | void; // async component factory function asyncMeta: Object | void; isAsyncPlaceholder: boolean; + isIgnoredElement: boolean; ssrContext: Object | void; functionalContext: Component | void; // real context vm for functional nodes functionalOptions: ?ComponentOptions; // for SSR caching @@ -58,6 +59,7 @@ export default class VNode { this.isComment = false this.isCloned = false this.isOnce = false + this.isIgnoredElement = false this.asyncFactory = asyncFactory this.asyncMeta = undefined this.isAsyncPlaceholder = false diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index c6018ed3437..3af8ef601ad 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -1,7 +1,6 @@ /* @flow */ import { isIE9, isEdge } from 'core/util/env' -import config from 'core/config' import { extend, @@ -39,14 +38,14 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { cur = attrs[key] old = oldAttrs[key] if (old !== cur) { - setAttr(elm, key, cur) + setAttr(elm, key, cur, vnode) } } // #4391: in IE9, setting type can reset value for input[type=radio] // #6666: IE/Edge forces progress value down to 1 before setting a max /* istanbul ignore if */ if ((isIE9 || isEdge) && attrs.value !== oldAttrs.value) { - setAttr(elm, 'value', attrs.value) + setAttr(elm, 'value', attrs.value, vnode) } for (key in oldAttrs) { if (isUndef(attrs[key])) { @@ -59,11 +58,11 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } } -function setAttr (el: Element, key: string, value: any) { +function setAttr (el: Element, key: string, value: any, vnode: ?VNodeWithData) { // The attributes are not set to their default values // for elements in the ignoredElements array // eg. - if (config.ignoredElements.indexOf(el.tagName.toLowerCase()) > -1) { + if (vnode && vnode.isIgnoredElement) { el.setAttribute(key, value) return } diff --git a/test/unit/features/global-api/config.spec.js b/test/unit/features/global-api/config.spec.js index 1edfc3c7829..6f4d28559d3 100644 --- a/test/unit/features/global-api/config.spec.js +++ b/test/unit/features/global-api/config.spec.js @@ -49,7 +49,7 @@ describe('Global config', () => { it('should work', () => { Vue.config.ignoredElements = ['foo', /^ion-/] new Vue({ - template: `
` + template: `
` }).$mount() expect('Unknown custom element').not.toHaveBeenWarned() Vue.config.ignoredElements = [] From 9e074d8f0ba280226ae6712eebab7448bcda1eb9 Mon Sep 17 00:00:00 2001 From: Zhenfei You Date: Wed, 13 Dec 2017 20:39:50 +0800 Subject: [PATCH 3/3] fix: remove unnecessary brackets --- src/core/vdom/patch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 88801ea2ee5..73fc4f2f65d 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -119,7 +119,7 @@ export function createPatchFunction (backend) { return ( !inVPre && !vnode.ns && - !(vnode.isIgnoredElement) && + !vnode.isIgnoredElement && config.isUnknownElement(vnode.tag) ) }