Skip to content

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Nov 8, 2025

Fixes #104 - Clear pending debounced sync when manual sync is triggered

…ytics

- Clear pending syncTimeout at start of syncEvents() method
- Prevents duplicate sync attempts when manual sync (e.g., handleOnline) is triggered
- Add 2 new tests to verify:
  1. Pending debounced sync is cancelled on manual sync
  2. No duplicate syncs occur from race condition
- Update comments to explain race condition prevention

Fixes #104

Tests:
- All 134 tests passing (2 new tests added for sync coordination)
- TypeScript: 0 errors
- ESLint: 0 warnings
- Prettier: compliant
- REUSE: compliant (3.3)
Copilot AI review requested due to automatic review settings November 8, 2025 08:30
@github-actions
Copy link

github-actions bot commented Nov 8, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a potential race condition where debounced sync operations could conflict with manual sync triggers. When the browser comes online or periodic sync fires, the manual syncEvents() call now cancels any pending debounced sync to prevent duplicate sync attempts.

Key Changes

  • Added timeout cancellation logic at the start of syncEvents() method
  • Added two comprehensive tests to verify the fix works correctly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/lib/analytics.ts Added logic to clear pending debounced sync timeout when manual sync is triggered, preventing duplicate sync attempts
src/lib/analytics.test.ts Added two tests verifying that pending debounced syncs are properly cancelled and that no duplicate syncs occur

@kevalyq kevalyq merged commit 1a3fd33 into main Nov 8, 2025
24 checks passed
@kevalyq kevalyq deleted the fix/issue-104-analytics-debounce-race branch November 8, 2025 09:02
@github-actions
Copy link

github-actions bot commented Nov 8, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

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.

PWA Phase 3: Fix debounce race condition in analytics sync

2 participants