Bug description
When a date and time have been chosen using the datetime picker, clicking on a different date might trigger a race condition, which causes the datetime picker to utilize an old version of its model. This results in displaying the time of a previous selection, instead of its current selection (i.e. model).
The bug is caused because the update function is called from within the view. This happens for example on this line, but there are multiple instances. This is considered bad practice in Elm. The model should only be updated from the update function, not from within the view itself. This might cause unpredictable behavior as described above.
To summarize what happens in terms of events:
- View rendered with PickerModel1
- We receive updated PickerModel2
- We render our own view with PickerModel2, but before that is completed a new event from the view sends us a PickerModel2B based on PickerModel1
How to reproduce
- Select a date and time using the datetime picker (e.g. 2022-05-07 12:30).
- Quickly select another date and time using the datetime picker (e.g. 2022-05-08 11:30).
- Quickly select another day (e.g. 2022-05-01).
- Most likely the time will be 12:30 instead of 11:30.
Please note, that the race condition might not always occur. Though, it is triggered more easily when selecting another date more quickly, shortly after changing the time.
Expected behavior
The datetime picker always utilizes the latest version of its model, and the time does not change when choosing another date.
Suggested change
Rewrite the datetime picker so the model is not updated from within the view, but from the update function instead. This is a major breaking change, hence I'm starting with the creation of this issue, rather than a PR.
If necessary, I could provide a screen capture exposing the bug.