]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): improve mismatch when client valut is null or undefined (#10086)
authorzhoulixiang <18366276315@163.com>
Fri, 12 Jan 2024 09:50:26 +0000 (17:50 +0800)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 09:50:26 +0000 (17:50 +0800)
packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/src/hydration.ts

index 3b2bdbf35c0894afe3ebc45238efac066b473aa0..c379485d6aa11e37ca43b74f29624692d9549ccb 100644 (file)
@@ -1512,6 +1512,16 @@ describe('SSR hydration', () => {
       expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
     })
 
+    test('client value is null or undefined', () => {
+      mountWithHydration(`<div></div>`, () =>
+        h('div', { draggable: undefined }),
+      )
+      expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
+
+      mountWithHydration(`<input />`, () => h('input', { type: null }))
+      expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
+    })
+
     test('should not warn against object values', () => {
       mountWithHydration(`<input />`, () => h('input', { from: {} }))
       expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
index 8ac4fbb75f7852e525976f31c6a01ce4481004dd..4970aee62bdc68babd6b940a1b80d5b72ad65bf1 100644 (file)
@@ -758,6 +758,9 @@ function propHasMismatch(
     if (isBooleanAttr(key)) {
       actual = el.hasAttribute(key)
       expected = includeBooleanAttr(clientValue)
+    } else if (clientValue == null) {
+      actual = el.hasAttribute(key)
+      expected = false
     } else {
       if (el.hasAttribute(key)) {
         actual = el.getAttribute(key)