Skip to content

fix(theme01): ignore stale commune responses - #108

Merged
bighadj22 merged 1 commit into
bighadj22:mainfrom
lianihossam-eng:fix/stale-commune-responses
Sep 11, 2026
Merged

fix(theme01): ignore stale commune responses#108
bighadj22 merged 1 commit into
bighadj22:mainfrom
lianihossam-eng:fix/stale-commune-responses

Conversation

@lianihossam-eng

Copy link
Copy Markdown

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:

  • stale successful response;
  • stale error response;
  • Alger → Oran → Alger ordering;
  • only the latest commune request updates the selector.

Validation

  • npm test — 21 tests passed
  • npx astro check — 0 errors
  • npm run build — passed
  • npm run validate — passed

@bighadj22
bighadj22 merged commit 72453e8 into bighadj22:main Sep 11, 2026
3 checks passed
@bighadj22

Copy link
Copy Markdown
Owner

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, astro check with 0 errors, and the full build/validators.

Merged into main 🎉

One small note for future PRs: the commit in this PR was authored as Test User <test@test.com>, so GitHub attributed it to a different account instead of yours your avatar doesn't show on the commit and it doesn't count toward your contribution graph (you still get full credit for the PR itself). To fix this for next time, set your git identity to the email linked to your GitHub account before committing:

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!

@lianihossam-eng

Copy link
Copy Markdown
Author

Blame my agent kho ! I’ll make sure to configure it correctly for future contributions. Looking forward to picking up
another issue! 🙌

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.

2 participants