marudor / bahn.expert

https://bahn.expert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition when switching dates

n-st opened this issue · comments

Describe the bug
A race condition can cause the user to end up at the wrong date when "clicking forward" through multiple dates.

To Reproduce

  1. Go to any train schedule page, e.g. https://bahn.expert/details/ICE119.
  2. Click the "next day >" button multiple times in quick succession.
  3. bahn.expert will start loading the schedule for each day we "passed" while clicking.
  4. Each schedule will be displayed as soon as it finishes loading — which might not happen in the order the loading started.
    When a schedule is displayed, the currently selected date is replaced with the date of the schedule.
    Combined with the slightly different loading times, this can cause the user to end up at an earlier date than the one they clicked to:

Example timeline:

  1. Date selector shows 2023-06-27.
  2. Click >.
  3. Date selector shows 2023-06-28 (schedule for 2023-06-28 starts loading in the background).
  4. Click >.
  5. Date selector shows 2023-06-29 (schedule for 2023-06-29 starts loading in the background).
  6. Click >.
  7. Date selector shows 2023-06-30 (schedule for 2023-06-30 starts loading in the background).
  8. Schedule for 2023-06-28 finished loading, and is displayed. Date selector is overwritten with 2023-06-28.
  9. Schedule for 2023-06-30 finished loading, and is displayed. Date selector is overwritten with 2023-06-30.
  10. Schedule for 2023-06-29 finished loading, and is displayed. Date selector is overwritten with 2023-06-29.
  11. User ends up at 2023-06-29, despite having already clicked further than that.

Expected behavior
Switching to a different day should just cancel all pending loads, since the user apparently doesn't wish to see them anymore anyway.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: Chrome
  • Version: 112.0