FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Only trigger 'selection:update' once on DOM change events by dbramwell · Pull Request #5734 · select2/select2 · GitHub

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

Merged
kevin-brown merged 5 commits into
select2:developfrom
dbramwell:develop
Jan 28, 2020
Merged

Only trigger 'selection:update' once on DOM change events#5734
kevin-brown merged 5 commits into
select2:developfrom
dbramwell:develop

Conversation

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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.
kevin-brown merged commit e0855a2 into select2:develop Jan 28, 2020
maxwellfet928 pushed a commit to maxwellfet928/select2 that referenced this pull request Jun 8, 2026
* Only trigger 'selection:update' once on DOM change events

* Fix linting errors

* Add test for adding multiple options to a select

* Switch Array.isArray to jQuery.isArray

Because we're still doing best-effort IE8 support for some reason.

* Fixed formatting in tests

Co-authored-by: Kevin Brown <kevin-brown@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL