diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index b5296db3c9d..73fc4f2f65d 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -104,18 +104,22 @@ export function createPatchFunction (backend) { } } + function isIgnoredElement (vnode) { + return ( + config.ignoredElements.length && + config.ignoredElements.some(ignore => { + return isRegExp(ignore) + ? ignore.test(vnode.tag) + : ignore === vnode.tag + }) + ) + } + function isUnknownElement (vnode, inVPre) { return ( !inVPre && !vnode.ns && - !( - config.ignoredElements.length && - config.ignoredElements.some(ignore => { - return isRegExp(ignore) - ? ignore.test(vnode.tag) - : ignore === vnode.tag - }) - ) && + !vnode.isIgnoredElement && config.isUnknownElement(vnode.tag) ) } @@ -131,6 +135,9 @@ export function createPatchFunction (backend) { const children = vnode.children const tag = vnode.tag if (isDef(tag)) { + if (isIgnoredElement(vnode)) { + vnode.isIgnoredElement = true + } if (process.env.NODE_ENV !== 'production') { if (data && data.pre) { creatingElmInVPre++ diff --git a/src/core/vdom/vnode.js b/src/core/vdom/vnode.js index 838f9f1e155..28efd915956 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; fnContext: Component | void; // real context vm for functional nodes fnOptions: ?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 0034d35e81d..de0009f6503 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -38,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 ((isIE || isEdge) && attrs.value !== oldAttrs.value) { - setAttr(elm, 'value', attrs.value) + setAttr(elm, 'value', attrs.value, vnode) } for (key in oldAttrs) { if (isUndef(attrs[key])) { @@ -58,7 +58,14 @@ 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 (vnode && vnode.isIgnoredElement) { + el.setAttribute(key, value) + return + } if (isBooleanAttr(key)) { // set attribute for blank value // e.g. 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 = []