]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compat): only warn ATTR_FALSE_VALUE when enabled
authorEvan You <yyx990803@gmail.com>
Fri, 14 Jun 2024 09:02:34 +0000 (11:02 +0200)
committerEvan You <yyx990803@gmail.com>
Fri, 14 Jun 2024 09:03:04 +0000 (11:03 +0200)
close #11126

packages/runtime-dom/src/modules/attrs.ts
packages/vue-compat/__tests__/misc.spec.ts

index 8218e182fb60175c6b8fdb23a6b491d59fe43a33..3cc3468a7757902628a6d72cdb83cc598ced2f37 100644 (file)
@@ -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
   }
index d9598be3738c040f0fe24dbc9753cea7771027b5..1a873633b85b44567f1ab5b362bbd334f8bcc323 100644 (file)
@@ -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" />`,