[Autocomplete] Fix 2 bugs where TomSelect would reset when not necessary #1502
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.
Hi!
The Autocomplete component "resets" the TomSelect instance under certain situations:
<option>
elements have changed<select>
changed itsmultiple
attributeBoth of these situations had a bug:
<option value"">
element, then each time a value was selected, it incorrectly looked like the options had changed, triggering a reset.<select multiple>
attribute was used without themultiple="multiple"
, it would incorrectly look like the multiple value was changing, when in fact it was just varying between these 2 valid formats.In both cases, when combined with LiveComponents, an infinite loop was triggered. That's because, as part of the reset process, when we recreate the TomSelect instance, we "select" the original value. This triggers a
change
event, causing LiveComponents to re-render. On its own , that's fine. But the re-render would trigger one of the bugs above, which would trigger another reset and another re-render.Cheers!