Skip to content

Commit d16a213

Browse files
committed
fix(hydration): fix incorect mismatch warning for option with non-string value and inner text
close 10140
1 parent e977c59 commit d16a213

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,5 +1531,12 @@ describe('SSR hydration', () => {
15311531
mountWithHydration(`<button />`, () => h('button', { href: undefined }))
15321532
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
15331533
})
1534+
1535+
test('should not warn on non-renderable option values', () => {
1536+
mountWithHydration(`<select><option>hello</option></select>`, () =>
1537+
h('select', [h('option', { value: ['foo'] }, 'hello')]),
1538+
)
1539+
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
1540+
})
15341541
})
15351542
})

packages/runtime-core/src/hydration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -764,16 +764,16 @@ function propHasMismatch(
764764
} else {
765765
if (el.hasAttribute(key)) {
766766
actual = el.getAttribute(key)
767+
} else if (key === 'value' && el.tagName === 'TEXTAREA') {
768+
// #10000 textarea.value can't be retrieved by `hasAttribute`
769+
actual = (el as HTMLTextAreaElement).value
767770
} else {
768-
// #10000 some attrs such as textarea.value can't be retrieved by `hasAttribute`
769-
const serverValue = el[key as keyof typeof el]
770-
actual =
771-
isObject(serverValue) || serverValue == null
772-
? ''
773-
: String(serverValue)
771+
actual = false
774772
}
775773
expected =
776-
isObject(clientValue) || clientValue == null ? '' : String(clientValue)
774+
isObject(clientValue) || clientValue == null
775+
? false
776+
: String(clientValue)
777777
}
778778
if (actual !== expected) {
779779
mismatchType = `attribute`

0 commit comments

Comments
 (0)