Skip to content

Unexpected DOM Updates When Wrapping Checkbox in a Vue Component #11647

@Mini-ghost

Description

@Mini-ghost

Vue version

v3.4.38

Link to minimal reproduction

https://play.vuejs.org/#eNp9VE1v2zAM/SuCL3EBz8G6nbIkxVYE2IZlLbpiO8w7ODGTqZMlQR9phiD/vZQU2WoS5GBAIh+pR/KZu+yjlOXGQjbKxnqpqDREg7FyWnHaSqEM2REFK7InKyVaMkDooHPd/oXlv4XYHnzlMBpcRoQtBdeGLJ0Rmrdk4jLlq5ppuDpyXh85x8NABmngxUArWW0Ab4SMKZfWkM2bVjTAJlUW81cZMf8lRAvSQMtoUzPrbJY3sKIcGjQOQ6KO/kmu6wNoPEyezorMaGS9ouvySQuOLdu5PBglWkkZqDtpKFZVZSPiPc5XMyaev3qbURaKaPcvnbE/aaQ9wsO9Ag1qA1XW+Uyt1mCCe/bjO2zx3DmxBMsQfcH5AFow6zgG2CdsCtJOcJ7tFz9dytePerY1wHUsyhF1yL3HVxlO+fZC6T3dd+V7H1fxPXYxVcmx7gir+RoHYTBVqkHB58JyA80rJX5IEG4IFgHFiV4RFeUmlZAatRa0cO9u+e+Bn/5PJ5RBgSH+8KeTKLTUdCEzvLgQKxtUxSiJdAExhIllzQ6S9k+WPbDL25t+KWrqBQOMiFXkvovYvvwqNlRhfxQPJST5yM1NeK/0xPv5YD9zb+oyuEryM9QLEnABlSRDQn1SHF5Sov8LH7DTvsrx58f5txmDFriZ5gjr5pVjAZNpYBAixQJjODyTuTW1U83dwgtdpdAAFgxKJtb5oD1AB55j4EEwUylCbB7pBN5FTFIbo+gCG6qT38yFu+/Skmnoxh+6fYNFoizjM7gf+qVxOsh08YQGntlN4aFheOn1ptm/ACJ26e0=

Steps to reproduce

  1. Open the Devtools Elements panel.
  2. Click on the first Checkbox, and notice that the corresponding <input> does not show any updates.
  3. Click on the second Checkbox, and observe that the corresponding <input> flickers (updates).
2024-08-19.12.28.35.mov

What is expected?

In this straightforward reproduction, the corresponding <input> DOM should not be updated when clicking on the Checkbox, as there are no updates besides modelValue.

What is actually happening?

The following code does not update the DOM, which is expected:

<input v-model="checked1" type="checkbox" :value="undefined" />

However, when this code is wrapped into a component, the DOM flickers (updates) every time the Checkbox is clicked.

Checkbox.vue

<script setup lang="ts">
import { computed } from 'vue';

const props = defineProps(['modelValue', 'value']);
const emit = defineEmits(['update:modelValue']);

const modelValueWritable = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit('update:modelValue', value);
  },
});
</script>

<template>
  <div>
    <input v-model="modelValueWritable" :value="value" type="checkbox">
  </div>
</template>
<Checkbox v-model="checked2" />

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1
    Memory: 80.08 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.9.0/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
    pnpm: 9.4.0 - ~/.nvm/versions/node/v20.9.0/bin/pnpm
  Browsers:
    Safari: 17.5
    Safari Technology Preview: 17.4
  npmPackages:
    vue: ^3.4.38 => 3.4.38

Any additional comments?

If the default value for value is changed to an empty string, this issue does not occur.

Link to reproduction 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.scope: v-model

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions