Skip to content

Commit 04729ba

Browse files
committedJun 14, 2024··
fix(compat): only warn ATTR_FALSE_VALUE when enabled
close #11126
1 parent 73fb15c commit 04729ba

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

‎packages/runtime-dom/src/modules/attrs.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export function compatCoerceAttr(
7676
} else if (
7777
value === false &&
7878
!isSpecialBooleanAttr(key) &&
79-
compatUtils.softAssertCompatEnabled(
79+
compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
80+
) {
81+
compatUtils.warnDeprecation(
8082
DeprecationTypes.ATTR_FALSE_VALUE,
8183
instance,
8284
key,
8385
)
84-
) {
8586
el.removeAttribute(key)
8687
return true
8788
}

‎packages/vue-compat/__tests__/misc.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,31 @@ test('ATTR_FALSE_VALUE', () => {
208208
).toHaveBeenWarned()
209209
})
210210

211+
test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
212+
const vm = new Vue({
213+
template: `<div :id="false" :foo="false"/>`,
214+
compatConfig: {
215+
ATTR_FALSE_VALUE: false,
216+
},
217+
}).$mount()
218+
219+
expect(vm.$el).toBeInstanceOf(HTMLDivElement)
220+
expect(vm.$el.hasAttribute('id')).toBe(true)
221+
expect(vm.$el.getAttribute('id')).toBe('false')
222+
expect(vm.$el.hasAttribute('foo')).toBe(true)
223+
expect(vm.$el.getAttribute('foo')).toBe('false')
224+
expect(
225+
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
226+
'id',
227+
),
228+
).not.toHaveBeenWarned()
229+
expect(
230+
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
231+
'foo',
232+
),
233+
).not.toHaveBeenWarned()
234+
})
235+
211236
test('ATTR_ENUMERATED_COERCION', () => {
212237
const vm = new Vue({
213238
template: `<div :draggable="null" :spellcheck="0" contenteditable="foo" />`,

0 commit comments

Comments
 (0)
Please sign in to comment.