Skip to content

Commit 3907c87

Browse files
committed
fix(hydration): should not warn on falsy bindings of non-property keys
1 parent 9636357 commit 3907c87

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,5 +1516,10 @@ describe('SSR hydration', () => {
15161516
mountWithHydration(`<input />`, () => h('input', { from: {} }))
15171517
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
15181518
})
1519+
1520+
test('should not warn on falsy bindings of non-property keys', () => {
1521+
mountWithHydration(`<button />`, () => h('button', { href: undefined }))
1522+
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
1523+
})
15191524
})
15201525
})

packages/runtime-core/src/hydration.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,18 +759,18 @@ function propHasMismatch(
759759
actual = el.hasAttribute(key)
760760
expected = includeBooleanAttr(clientValue)
761761
} else {
762-
// #10000 some attrs such as textarea.value can't be get by `hasAttribute`
763762
if (el.hasAttribute(key)) {
764763
actual = el.getAttribute(key)
765-
} else if (key in el) {
764+
} else {
765+
// #10000 some attrs such as textarea.value can't be retrieved by `hasAttribute`
766766
const serverValue = el[key as keyof typeof el]
767-
if (!isObject(serverValue)) {
768-
actual = serverValue == null ? '' : String(serverValue)
769-
}
770-
}
771-
if (!isObject(clientValue)) {
772-
expected = clientValue == null ? '' : String(clientValue)
767+
actual =
768+
isObject(serverValue) || serverValue == null
769+
? ''
770+
: String(serverValue)
773771
}
772+
expected =
773+
isObject(clientValue) || clientValue == null ? '' : String(clientValue)
774774
}
775775
if (actual !== expected) {
776776
mismatchType = `attribute`

0 commit comments

Comments
 (0)