Skip to content

Commit

Permalink
fix(compat): only warn ATTR_FALSE_VALUE when enabled
Browse files Browse the repository at this point in the history
close #11126
  • Loading branch information
yyx990803 committed Jun 14, 2024
1 parent 73fb15c commit 04729ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/runtime-dom/src/modules/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export function compatCoerceAttr(
} else if (
value === false &&
!isSpecialBooleanAttr(key) &&
compatUtils.softAssertCompatEnabled(
compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
) {
compatUtils.warnDeprecation(
DeprecationTypes.ATTR_FALSE_VALUE,
instance,
key,
)
) {
el.removeAttribute(key)
return true
}
Expand Down
25 changes: 25 additions & 0 deletions packages/vue-compat/__tests__/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ test('ATTR_FALSE_VALUE', () => {
).toHaveBeenWarned()
})

test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
const vm = new Vue({
template: `<div :id="false" :foo="false"/>`,
compatConfig: {
ATTR_FALSE_VALUE: false,
},
}).$mount()

expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(true)
expect(vm.$el.getAttribute('id')).toBe('false')
expect(vm.$el.hasAttribute('foo')).toBe(true)
expect(vm.$el.getAttribute('foo')).toBe('false')
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'id',
),
).not.toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'foo',
),
).not.toHaveBeenWarned()
})

test('ATTR_ENUMERATED_COERCION', () => {
const vm = new Vue({
template: `<div :draggable="null" :spellcheck="0" contenteditable="foo" />`,
Expand Down

0 comments on commit 04729ba

Please sign in to comment.