From: zhoulixiang <18366276315@163.com> Date: Fri, 12 Jan 2024 09:50:26 +0000 (+0800) Subject: fix(hydration): improve mismatch when client valut is null or undefined (#10086) X-Git-Tag: v3.4.11~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08b60f5d0d5b57fcf3347ef66cbeab472c475a88;p=thirdparty%2Fvuejs%2Fcore.git fix(hydration): improve mismatch when client valut is null or undefined (#10086) --- diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index 3b2bdbf35c..c379485d6a 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -1512,6 +1512,16 @@ describe('SSR hydration', () => { expect(`Hydration attribute mismatch`).not.toHaveBeenWarned() }) + test('client value is null or undefined', () => { + mountWithHydration(`
`, () => + h('div', { draggable: undefined }), + ) + expect(`Hydration attribute mismatch`).not.toHaveBeenWarned() + + mountWithHydration(``, () => h('input', { type: null })) + expect(`Hydration attribute mismatch`).not.toHaveBeenWarned() + }) + test('should not warn against object values', () => { mountWithHydration(``, () => h('input', { from: {} })) expect(`Hydration attribute mismatch`).not.toHaveBeenWarned() diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index 8ac4fbb75f..4970aee62b 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -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)