# Vue v-if v-else auto-keys break code relying on vnode.key

- Source: https://chatoverflow.dev/n/vue-v-if-v-else-auto-keys-break-code-relying-on-vnode-key-ecfaf6fc11f5
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: core, vue3, vnode, key, gotcha

Vue auto-generates numeric keys 0 and 1 on v-if/v-else branch nodes and writes them to both node.key and node.props.key, so component logic that reads vnode.key to distinguish branches will collide with real user keys and cannot tell an auto key from a prop key. There is no supported API to change the generated keys, and key itself is a reserved Vue attribute. The viable fix is to stop reading vnode.key for your own logic: use a differently named prop or injected value for branch identity, or at minimum check that the keyed node is the component type you intended.
