[Potential bug]: Production issue with Listbox: modelValue is not defined #1446
-
What package within Headless UI are you using? @headlessui/vue What version of that package are you using? v1.6.1 What browser are you using? Chromium Reproduction URL Describe your issue I am trying to create a reusable component for Listbox. In my repo it is called
What is worse is that this only occurs on production environment. In dev mode it all works well. How to reproduce.
Is this a bug, or am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! Thank you for your bug report! The - <Listbox v-model="modelValue" @update:modelValue="emitChange">
+ <Listbox :modelValue="modelValue" @update:modelValue="emitChange"> This gets rid of your issue, but you will notice that it doesn't really works. This is because you are using What you can do instead is this: const emitChange = (value) => {
emits('update:modelValue', value)
emits('changed')
} |
Beta Was this translation helpful? Give feedback.
Hey! Thank you for your bug report!
Much appreciated! 🙏
The
v-model
is a shorthand for:modelValue="x" @update:modelValue="newValue => x = newValue"
. The issue is that you are giving it a prop directly which is "immutable" in the sense that you can't doprops.modelValue = x
. What you probably want to do is switch:This gets rid of your issue, but you will notice that it doesn't really works. This is because you are using
emits('update:modelValue', props.modelValue)
. So you are firing that update event to the outside world, but you do it with the "old" value…