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

Only trigger 'selection:update' once on DOM change events #5734

Merged
merged 5 commits into from
Jan 28, 2020

Conversation

dbramwell
Copy link
Contributor

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • Rather than triggering DOM updates for every mutation within the select, only do it once if at least one mutation is detected.

I've had an issue when using select2 with datatables editor. I have a dropdown that has 4000+ elements, loaded via datatables editor and ajax. Everytime I filter/sort/change page on the table a new request fires to get the data the correct page, but also (annoyingly and seemingly unnecessarily) the list of options for the dropdown gets returned again... This then causes the page to become unresponsive as select2 goes through and refreshes the DOM (I think, it's certainly doing something along those lines) 4000+ times for each option being removed, and 4000+ times for each option being added.

This issue didn't exist before 4.0.3, and the below changes fix it. All tests are still passing, but I could very easily have overlooked something important though.

@kevin-brown
Copy link
Member

Is it possible to add a test that covers this change? It would probably be similar to the existing DOM integration tests, but for handling multiple changes.

@dbramwell
Copy link
Contributor Author

Happy to give it a try, yes. Should I just be testing that selection:update only happens once? Kind of tricky without making the test "wait" for a little bit to check it doesn't get called more than once.

@dbramwell
Copy link
Contributor Author

The test I've added fails before my change, but I'm not sure how useful the test case is... Let me know your thoughts

Because we're still doing best-effort IE8 support for some reason.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants