Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #6864: don't set ignoredElements' attributes to their default values #6885

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand All @@ -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++
Expand Down
2 changes: 2 additions & 0 deletions src/core/vdom/vnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/platforms/web/runtime/modules/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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. <custom-tab-bar selected="tab1"></custom-tab-bar>
if (vnode && vnode.isIgnoredElement) {
el.setAttribute(key, value)
return
}
if (isBooleanAttr(key)) {
// set attribute for blank value
// e.g. <option disabled>Select one</option>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/features/global-api/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Global config', () => {
it('should work', () => {
Vue.config.ignoredElements = ['foo', /^ion-/]
new Vue({
template: `<div><foo/><ion-foo/><ion-bar/></div>`
template: `<div><foo selected="tab1"/><ion-foo/><ion-bar/></div>`
}).$mount()
expect('Unknown custom element').not.toHaveBeenWarned()
Vue.config.ignoredElements = []
Expand Down