]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compat): ensure false value on input retains value attribute (#13216)
authoredison <daiwei521@126.com>
Tue, 20 May 2025 00:43:51 +0000 (08:43 +0800)
committerGitHub <noreply@github.com>
Tue, 20 May 2025 00:43:51 +0000 (08:43 +0800)
close #13205

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

index 95e0a14854af541f96e686e4aa05e2760e8e5a7c..d7188aa9a1f61905405c6600dd482249bea7965a 100644 (file)
@@ -79,6 +79,7 @@ export function compatCoerceAttr(
     }
   } else if (
     value === false &&
+    !(el.tagName === 'INPUT' && key === 'value') &&
     !isSpecialBooleanAttr(key) &&
     compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
   ) {
index 1a873633b85b44567f1ab5b362bbd334f8bcc323..17fddd94c4addfcfeebe1db2b4e5a04100874578 100644 (file)
@@ -208,6 +208,20 @@ test('ATTR_FALSE_VALUE', () => {
   ).toHaveBeenWarned()
 })
 
+test('ATTR_FALSE_VALUE with false on input value', () => {
+  const vm = new Vue({
+    template: `<input :value="false"/>`,
+  }).$mount()
+  expect(vm.$el).toBeInstanceOf(HTMLInputElement)
+  expect(vm.$el.hasAttribute('value')).toBe(true)
+  expect(vm.$el.getAttribute('value')).toBe('false')
+  expect(
+    (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
+      'value',
+    ),
+  ).not.toHaveBeenWarned()
+})
+
 test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
   const vm = new Vue({
     template: `<div :id="false" :foo="false"/>`,