Skip to content

Commit

Permalink
fix(hydration): should not warn on falsy bindings of non-property keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 11, 2024
1 parent 9636357 commit 3907c87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,5 +1516,10 @@ describe('SSR hydration', () => {
mountWithHydration(`<input />`, () => h('input', { from: {} }))
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})

test('should not warn on falsy bindings of non-property keys', () => {
mountWithHydration(`<button />`, () => h('button', { href: undefined }))
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})
})
})
16 changes: 8 additions & 8 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,18 +759,18 @@ function propHasMismatch(
actual = el.hasAttribute(key)
expected = includeBooleanAttr(clientValue)
} else {
// #10000 some attrs such as textarea.value can't be get by `hasAttribute`
if (el.hasAttribute(key)) {
actual = el.getAttribute(key)
} else if (key in el) {
} else {
// #10000 some attrs such as textarea.value can't be retrieved by `hasAttribute`
const serverValue = el[key as keyof typeof el]
if (!isObject(serverValue)) {
actual = serverValue == null ? '' : String(serverValue)
}
}
if (!isObject(clientValue)) {
expected = clientValue == null ? '' : String(clientValue)
actual =
isObject(serverValue) || serverValue == null
? ''
: String(serverValue)
}
expected =
isObject(clientValue) || clientValue == null ? '' : String(clientValue)
}
if (actual !== expected) {
mismatchType = `attribute`
Expand Down

0 comments on commit 3907c87

Please sign in to comment.