Skip to content

Commit bfeab17

Browse files
committed
fix: add warning for v1 boolean attribute syntax
1 parent be5f1d0 commit bfeab17

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/shared/merge.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import deepmerge from 'deepmerge'
22
import { findIndex } from '../utils/array'
33
import { applyTemplate } from './template'
4-
import { metaInfoAttributeKeys } from './constants'
4+
import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants'
55

66
export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
77
// we concat the arrays without merging objects contained in,
@@ -80,6 +80,10 @@ export function merge(target, source, options = {}) {
8080

8181
for (const key in source[attrKey]) {
8282
if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) {
83+
if (booleanHtmlAttributes.includes(key)) {
84+
// eslint-disable-next-line no-console
85+
console.warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details')
86+
}
8387
delete source[attrKey][key]
8488
}
8589
}

test/unit/getMetaInfo.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,36 @@ describe('getMetaInfo', () => {
820820
__dangerouslyDisableSanitizersByTagID: {}
821821
})
822822
})
823+
824+
test.only('prints warning for boolean attributes with value undefined', () => {
825+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
826+
827+
const component = new Vue({
828+
metaInfo: {
829+
htmlAttrs: {
830+
amp: undefined
831+
}
832+
}
833+
})
834+
835+
expect(getMetaInfo(component)).toEqual({
836+
title: undefined,
837+
titleChunk: '',
838+
titleTemplate: '%s',
839+
htmlAttrs: {},
840+
headAttrs: {},
841+
bodyAttrs: {},
842+
meta: [],
843+
base: [],
844+
link: [],
845+
style: [],
846+
script: [],
847+
noscript: [],
848+
__dangerouslyDisableSanitizers: [],
849+
__dangerouslyDisableSanitizersByTagID: {}
850+
})
851+
852+
expect(warn).toHaveBeenCalledTimes(1)
853+
expect(warn).toHaveBeenCalledWith(expect.stringMatching('the value undefined'))
854+
})
823855
})

0 commit comments

Comments
 (0)