josefarias / hotwire_combobox

An accessible autocomplete for Ruby on Rails.
https://hotwirecombobox.com
MIT License
496 stars 32 forks source link

Create callback queue to run callbacks in order #191

Closed josefarias closed 2 months ago

josefarias commented 3 months ago

Closes https://github.com/josefarias/hotwire_combobox/issues/180

Relying on callbacks kicked off by server streams is prone to race conditions when actions happen in rapid sequence.

In the case of the linked issue, we were calling the this._selectOnQuery branch after locking in selection:

if () {
  // ...
}
else if (inputType && inputType !== "hw:lockInSelection") {
  if (delay) await sleep(delay)
  this._selectOnQuery(inputType)
}

This fix works but I want to clean it up before merging