Skip to content

Commit

Permalink
fix: add hydration mismatch checks for attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-lx committed Jan 5, 2024
1 parent 4f67aa0 commit d563f66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,9 @@ describe('SSR hydration', () => {
mountWithHydration(`<textarea>foo</textarea>`, () =>
h('textarea', { value: 'foo' }),
)
mountWithHydration(`<textarea></textarea>`, () =>
h('textarea', { value: '' }),
)
expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()

mountWithHydration(`<div></div>`, () => h('div', { id: 'foo' }))
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,15 +739,15 @@ function propHasMismatch(el: Element, key: string, clientValue: any): boolean {
) {
actual = el.hasAttribute(key)
? el.getAttribute(key)
: el[key as keyof typeof el]
: key in el
? el[key as keyof typeof el]
: false
: ''
expected = isBooleanAttr(key)
? includeBooleanAttr(clientValue)
? ''
: false
: clientValue == null
? false
? ''
: String(clientValue)
if (actual !== expected) {
mismatchType = `attribute`
Expand Down

0 comments on commit d563f66

Please sign in to comment.