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

Prevent rendering fetch results arriving out of order #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

til
Copy link

@til til commented Feb 2, 2025

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 .

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

netlify bot commented Feb 2, 2025

Deploy Preview for stimulus-autocomplete canceled.

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

@til
Copy link
Author

til commented Feb 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant