Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: process some keys for el[key] in hydration mismatch #10060

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1489,5 +1489,10 @@ describe('SSR hydration', () => {
mountWithHydration(`<div id="bar"></div>`, () => h('div', { id: 'foo' }))
expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(2)
})

test('attr need to be processed mismatch', () => {
mountWithHydration(`<input />`, () => h('input', { readonly: false }))
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})
})
})
14 changes: 12 additions & 2 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,11 @@ function propHasMismatch(
(el instanceof HTMLElement && (isBooleanAttr(key) || isKnownHtmlAttr(key)))
) {
// #10000 some attrs such as textarea.value can't be get by `hasAttribute`
const processedKey = getProcessedKey(key)
actual = el.hasAttribute(key)
? el.getAttribute(key)
: key in el
? el[key as keyof typeof el]
: processedKey in el
? el[processedKey as keyof typeof el]
: ''
expected = isBooleanAttr(key)
? includeBooleanAttr(clientValue)
Expand Down Expand Up @@ -830,3 +831,12 @@ function isMapEqual(a: Map<string, string>, b: Map<string, string>): boolean {
}
return true
}

// Some keys need to be processed before they can be obtained by el[key]
// #10057 such as: readonly => readOnly
function getProcessedKey(key: string) {
if (key === 'readonly') {
return 'readOnly'
}
return key
}