Skip to content

Commit

Permalink
fix(hydration): fix incorect mismatch warning for option with non-str…
Browse files Browse the repository at this point in the history
…ing value and inner text

close 10140
  • Loading branch information
yyx990803 committed Jan 18, 2024
1 parent e977c59 commit d16a213
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,5 +1531,12 @@ describe('SSR hydration', () => {
mountWithHydration(`<button />`, () => h('button', { href: undefined }))
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})

test('should not warn on non-renderable option values', () => {
mountWithHydration(`<select><option>hello</option></select>`, () =>
h('select', [h('option', { value: ['foo'] }, 'hello')]),
)
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
})
})
})
14 changes: 7 additions & 7 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,16 +764,16 @@ function propHasMismatch(
} else {
if (el.hasAttribute(key)) {
actual = el.getAttribute(key)
} else if (key === 'value' && el.tagName === 'TEXTAREA') {
// #10000 textarea.value can't be retrieved by `hasAttribute`
actual = (el as HTMLTextAreaElement).value
} else {
// #10000 some attrs such as textarea.value can't be retrieved by `hasAttribute`
const serverValue = el[key as keyof typeof el]
actual =
isObject(serverValue) || serverValue == null
? ''
: String(serverValue)
actual = false
}
expected =
isObject(clientValue) || clientValue == null ? '' : String(clientValue)
isObject(clientValue) || clientValue == null
? false
: String(clientValue)
}
if (actual !== expected) {
mismatchType = `attribute`
Expand Down

0 comments on commit d16a213

Please sign in to comment.