Combobox and listbox: Save optionKey in x-data to fix usage in Livewire #3990
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I created a listbox (or combobox) with options that are present in HTML and not generated by javascript.
When I use the listbox/combobox in a livewire component and a livewire update is triggered (by clicking the "trigger livewire update" button in the example above), then the following javascript warnings and errors occur:
When I debugged the issue, I discovered that the
__optionKey
on the option HTML element disappears after the Livewire update. To fix that, I updated the listbox/combobox code so that the "optionKey" is saved in the Alpinejs' x-data as that data will not be disappear after a Livewire update.I did not add tests because I'm unsure how to test this as Livewire causes it.
This issue and another Livewire-related issue (livewire/livewire#7566) are currently the only 2 bugs preventing me from using the listbox/combobox in Livewire. I have tried to debug the other issue, but after many hours of searching, I have still not found what is causing the infinite loop.