Skip to content

Commit

Permalink
fix(hydration): properly hydrate indeterminate prop
Browse files Browse the repository at this point in the history
close #7476
  • Loading branch information
yyx990803 committed Nov 10, 2023
1 parent 0e1e8f9 commit 34b5a5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,20 @@ describe('SSR hydration', () => {
expect((container.firstChild as any)._trueValue).toBe(true)
})

test('force hydrate checkbox with indeterminate', () => {
const { container } = mountWithHydration(
'<input type="checkbox" indeterminate>',
() =>
createVNode(
'input',
{ type: 'checkbox', indeterminate: '' },
null,
PatchFlags.HOISTED
)
)
expect((container.firstChild as any).indeterminate).toBe(true)
})

test('force hydrate select option with non-string value bindings', () => {
const { container } = mountWithHydration(
'<select><option :value="true">ok</option></select>',
Expand Down
10 changes: 6 additions & 4 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,25 @@ export function createHydrationFunctions(
const { type, props, patchFlag, shapeFlag, dirs, transition } = vnode
// #4006 for form elements with non-string v-model value bindings
// e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
const forcePatchValue = (type === 'input' && dirs) || type === 'option'
// #7476 <input indeterminate>
const forcePatch = type === 'input' || type === 'option'
// skip props & children if this is hoisted static nodes
// #5405 in dev, always hydrate children for HMR
if (__DEV__ || forcePatchValue || patchFlag !== PatchFlags.HOISTED) {
if (__DEV__ || forcePatch || patchFlag !== PatchFlags.HOISTED) {
if (dirs) {
invokeDirectiveHook(vnode, null, parentComponent, 'created')
}
// props
if (props) {
if (
forcePatchValue ||
forcePatch ||
!optimized ||
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.HYDRATE_EVENTS)
) {
for (const key in props) {
if (
(forcePatchValue && key.endsWith('value')) ||
(forcePatch &&
(key.endsWith('value') || key === 'indeterminate')) ||
(isOn(key) && !isReservedProp(key))
) {
patchProp(
Expand Down

0 comments on commit 34b5a5d

Please sign in to comment.