fix(theme01): ignore stale commune responses - #108
Conversation
|
Hi @lianihossam-eng, thanks for this fix — nicely done! 👏 The race condition reproduction was spot-on, the request-ID guard is clean and minimal, and the regression tests you added cover all the important orderings (stale success, stale error, and rapid wilaya switching). Everything passed our full validation: 21/21 tests, Merged into One small note for future PRs: the commit in this PR was authored as git config user.name "lianihossam-eng"
git config user.email "<email-linked-to-your-github-account>"Thanks again, and feel free to pick up another issue! |
|
Blame my agent kho ! I’ll make sure to configure it correctly for future contributions. Looking forward to picking up |
Problem
When users change the wilaya quickly, multiple commune requests can be in flight at the same time.
An older response may arrive after the latest response and overwrite the commune selector with stale data. The same issue can happen when an older request fails: its error handler can clear the valid communes loaded by the latest request.
Example:
Alger request pending → select Oran → Oran communes displayed → Alger response arrives → Alger communes overwrite Oran communes.
Solution
Assign a monotonically increasing request ID to each commune request.
A response or error handler updates the commune selector only if its request ID matches the latest request ID. This prevents stale success and stale error responses from modifying the selector.
The fix also covers rapid changes such as Alger → Oran → Alger.
The API, database schema, and dependencies are unchanged.
Tests
Added regression tests covering:
Validation
npm test— 21 tests passednpx astro check— 0 errorsnpm run build— passednpm run validate— passed