Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix 2 bugs where TomSelect would reset when not necessary #1502

Merged
merged 1 commit into from Feb 16, 2024

Conversation

weaverryan
Copy link
Member

Q A
Bug fix? yes
New feature? no
Issues Fix #1499
License MIT

Hi!

The Autocomplete component "resets" the TomSelect instance under certain situations:

  • A) The underlying <option> elements have changed
  • B) The <select> changed its multiple attribute

Both of these situations had a bug:

  • A) If there was no empty <option value""> element, then each time a value was selected, it incorrectly looked like the options had changed, triggering a reset.
  • B) If the <select multiple> attribute was used without the multiple="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!

@yceruto
Copy link
Member

yceruto commented Feb 15, 2024

Hey Ryan! do you think this PR will also fix this issue #1500?

@weaverryan
Copy link
Member Author

Hey Ryan! do you think this PR will also fix this issue #1500?

Checking that now. I don't think it will - this PR is about resetting less. That issue is about needing MORE resetting 🙃

@weaverryan weaverryan merged commit 529f074 into symfony:2.x Feb 16, 2024
31 of 33 checks passed
@weaverryan weaverryan deleted the autocomplete-fix-over-resetting branch February 16, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] + [LiveComponent] Infinite loop of requests with data-model on autocomplete.
3 participants