]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): properly hydrate indeterminate prop
authorEvan You <yyx990803@gmail.com>
Fri, 10 Nov 2023 04:04:22 +0000 (12:04 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 10 Nov 2023 04:19:27 +0000 (12:19 +0800)
close #7476

packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/src/hydration.ts

index 50331d0623f7ea379a0483932d7961ac723f66bf..e54960222c4ef61c9012870da08a8db9b2d13c82 100644 (file)
@@ -953,6 +953,20 @@ describe('SSR hydration', () => {
     expect((container.firstChild as any)._trueValue).toBe(true)
   })
 
+  test('force hydrate checkbox with indeterminate', () => {
+    const { container } = mountWithHydration(
+      '<input type="checkbox" indeterminate>',
+      () =>
+        createVNode(
+          'input',
+          { type: 'checkbox', indeterminate: '' },
+          null,
+          PatchFlags.HOISTED
+        )
+    )
+    expect((container.firstChild as any).indeterminate).toBe(true)
+  })
+
   test('force hydrate select option with non-string value bindings', () => {
     const { container } = mountWithHydration(
       '<select><option :value="true">ok</option></select>',
index b8940e6679a8d547cfeac8465af3a05f0f1b0d51..0e94495878ed70cacd83eab54a4bf17ea158efec 100644 (file)
@@ -321,23 +321,25 @@ export function createHydrationFunctions(
     const { type, props, patchFlag, shapeFlag, dirs, transition } = vnode
     // #4006 for form elements with non-string v-model value bindings
     // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
-    const forcePatchValue = (type === 'input' && dirs) || type === 'option'
+    // #7476 <input indeterminate>
+    const forcePatch = type === 'input' || type === 'option'
     // skip props & children if this is hoisted static nodes
     // #5405 in dev, always hydrate children for HMR
-    if (__DEV__ || forcePatchValue || patchFlag !== PatchFlags.HOISTED) {
+    if (__DEV__ || forcePatch || patchFlag !== PatchFlags.HOISTED) {
       if (dirs) {
         invokeDirectiveHook(vnode, null, parentComponent, 'created')
       }
       // props
       if (props) {
         if (
-          forcePatchValue ||
+          forcePatch ||
           !optimized ||
           patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.HYDRATE_EVENTS)
         ) {
           for (const key in props) {
             if (
-              (forcePatchValue && key.endsWith('value')) ||
+              (forcePatch &&
+                (key.endsWith('value') || key === 'indeterminate')) ||
               (isOn(key) && !isReservedProp(key))
             ) {
               patchProp(