Prevent rendering fetch results arriving out of order
Before, a slow server response arriving after the response to a later request would cause outdated results to be rendered.
Example sequence of events:
- user types "ab", request for q=ab starts
- user types "cd", request for q=abcd starts
- response for q=abcd arrives and is rendered
- 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".
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 .
Deploy Preview for stimulus-autocomplete canceled.
| Name | Link |
|---|---|
| Latest commit | df42d0ffc704853952128ae5597ccc9b2363c4fe |
| Latest deploy log | https://app.netlify.com/sites/stimulus-autocomplete/deploys/679ffe70e06f8300084e3931 |
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.