stimulus-autocomplete icon indicating copy to clipboard operation
stimulus-autocomplete copied to clipboard

Prevent rendering fetch results arriving out of order

Open til opened this issue 11 months ago • 2 comments

Before, a slow server response arriving after the response to a later request would cause outdated results to be rendered.

Example sequence of events:

  1. user types "ab", request for q=ab starts
  2. user types "cd", request for q=abcd starts
  3. response for q=abcd arrives and is rendered
  4. response for q=ab arrives and should be discarded

I've reproduced it locally with a test server that echos the search with "You searched for ..." and artificially delays the response to q=ab by 2s. At the end of the video, it shows "You searched for ab", but it should show "You searched for abcd".

out-of-order


Give me a hint how to test this with cypress and I can give it a try. Something with intercept returning a promise?

Somewhat related to #137 .

til avatar Feb 02 '25 23:02 til

Deploy Preview for stimulus-autocomplete canceled.

Name Link
Latest commit df42d0ffc704853952128ae5597ccc9b2363c4fe
Latest deploy log https://app.netlify.com/sites/stimulus-autocomplete/deploys/679ffe70e06f8300084e3931

netlify[bot] avatar Feb 02 '25 23:02 netlify[bot]

I should add that I've experienced this behaviour in production on a server with high variability in search response time (20ms-1000ms) and data-autocomplete-delay-value set to 100. Without these two factors, you might never see it.

til avatar Feb 02 '25 23:02 til