Skip to content

Commit

Permalink
fix(runtime-dom): prevent unnecessary updates in v-model checkbox whe…
Browse files Browse the repository at this point in the history
…n value is unchanged
  • Loading branch information
jh-leong committed Oct 11, 2024
1 parent 35785f3 commit cd9d697
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/runtime-dom/src/directives/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const vModelCheckbox: ModelDirective<HTMLInputElement> = {

function setChecked(
el: HTMLInputElement,
{ value }: DirectiveBinding,
{ value, oldValue }: DirectiveBinding,
vnode: VNode,
) {
// store the v-model value on the element so it can be accessed by the
Expand All @@ -173,7 +173,10 @@ function setChecked(
} else if (isSet(value)) {
checked = value.has(vnode.props!.value)
} else {
checked = looseEqual(value, getCheckboxValue(el, true))
checked =
value === oldValue
? el.checked
: looseEqual(value, getCheckboxValue(el, true))
}

// Only update if the checked state has changed
Expand Down

0 comments on commit cd9d697

Please sign in to comment.