mirror of https://github.com/vuejs/core.git
fix(hydration): improve attr hydration mismatch check for boolean attrs
close #10057 close #10060
This commit is contained in:
parent
d60a57542b
commit
972facee0d
|
@ -1489,5 +1489,20 @@ describe('SSR hydration', () => {
|
||||||
mountWithHydration(`<div id="bar"></div>`, () => h('div', { id: 'foo' }))
|
mountWithHydration(`<div id="bar"></div>`, () => h('div', { id: 'foo' }))
|
||||||
expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(2)
|
expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('boolean attr handling', () => {
|
||||||
|
mountWithHydration(`<input />`, () => h('input', { readonly: false }))
|
||||||
|
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
|
||||||
|
|
||||||
|
mountWithHydration(`<input readonly />`, () =>
|
||||||
|
h('input', { readonly: true }),
|
||||||
|
)
|
||||||
|
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
|
||||||
|
|
||||||
|
mountWithHydration(`<input readonly="readonly" />`, () =>
|
||||||
|
h('input', { readonly: true }),
|
||||||
|
)
|
||||||
|
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -754,19 +754,18 @@ function propHasMismatch(
|
||||||
(el instanceof SVGElement && isKnownSvgAttr(key)) ||
|
(el instanceof SVGElement && isKnownSvgAttr(key)) ||
|
||||||
(el instanceof HTMLElement && (isBooleanAttr(key) || isKnownHtmlAttr(key)))
|
(el instanceof HTMLElement && (isBooleanAttr(key) || isKnownHtmlAttr(key)))
|
||||||
) {
|
) {
|
||||||
// #10000 some attrs such as textarea.value can't be get by `hasAttribute`
|
if (isBooleanAttr(key)) {
|
||||||
actual = el.hasAttribute(key)
|
actual = el.hasAttribute(key)
|
||||||
? el.getAttribute(key)
|
expected = includeBooleanAttr(clientValue)
|
||||||
: key in el
|
} else {
|
||||||
? el[key as keyof typeof el]
|
// #10000 some attrs such as textarea.value can't be get by `hasAttribute`
|
||||||
: ''
|
actual = el.hasAttribute(key)
|
||||||
expected = isBooleanAttr(key)
|
? el.getAttribute(key)
|
||||||
? includeBooleanAttr(clientValue)
|
: key in el
|
||||||
? ''
|
? el[key as keyof typeof el]
|
||||||
: false
|
: ''
|
||||||
: clientValue == null
|
expected = clientValue == null ? '' : String(clientValue)
|
||||||
? ''
|
}
|
||||||
: String(clientValue)
|
|
||||||
if (actual !== expected) {
|
if (actual !== expected) {
|
||||||
mismatchType = `attribute`
|
mismatchType = `attribute`
|
||||||
mismatchKey = key
|
mismatchKey = key
|
||||||
|
|
Loading…
Reference in New Issue