Skip to content

Commit 34b5a5d

Browse files
committedNov 10, 2023
fix(hydration): properly hydrate indeterminate prop
close #7476
1 parent 0e1e8f9 commit 34b5a5d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
 

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

+14
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,20 @@ describe('SSR hydration', () => {
953953
expect((container.firstChild as any)._trueValue).toBe(true)
954954
})
955955

956+
test('force hydrate checkbox with indeterminate', () => {
957+
const { container } = mountWithHydration(
958+
'<input type="checkbox" indeterminate>',
959+
() =>
960+
createVNode(
961+
'input',
962+
{ type: 'checkbox', indeterminate: '' },
963+
null,
964+
PatchFlags.HOISTED
965+
)
966+
)
967+
expect((container.firstChild as any).indeterminate).toBe(true)
968+
})
969+
956970
test('force hydrate select option with non-string value bindings', () => {
957971
const { container } = mountWithHydration(
958972
'<select><option :value="true">ok</option></select>',

‎packages/runtime-core/src/hydration.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,25 @@ export function createHydrationFunctions(
321321
const { type, props, patchFlag, shapeFlag, dirs, transition } = vnode
322322
// #4006 for form elements with non-string v-model value bindings
323323
// e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
324-
const forcePatchValue = (type === 'input' && dirs) || type === 'option'
324+
// #7476 <input indeterminate>
325+
const forcePatch = type === 'input' || type === 'option'
325326
// skip props & children if this is hoisted static nodes
326327
// #5405 in dev, always hydrate children for HMR
327-
if (__DEV__ || forcePatchValue || patchFlag !== PatchFlags.HOISTED) {
328+
if (__DEV__ || forcePatch || patchFlag !== PatchFlags.HOISTED) {
328329
if (dirs) {
329330
invokeDirectiveHook(vnode, null, parentComponent, 'created')
330331
}
331332
// props
332333
if (props) {
333334
if (
334-
forcePatchValue ||
335+
forcePatch ||
335336
!optimized ||
336337
patchFlag & (PatchFlags.FULL_PROPS | PatchFlags.HYDRATE_EVENTS)
337338
) {
338339
for (const key in props) {
339340
if (
340-
(forcePatchValue && key.endsWith('value')) ||
341+
(forcePatch &&
342+
(key.endsWith('value') || key === 'indeterminate')) ||
341343
(isOn(key) && !isReservedProp(key))
342344
) {
343345
patchProp(

0 commit comments

Comments
 (0)
Please sign in to comment.