Skip to content

Conversation

@Toba-bonjour
Copy link

@Toba-bonjour Toba-bonjour commented Dec 22, 2025

🎯 Changes

Raw changes

  • Added isOnline(): boolean to OnlineDetector interface
  • Added onlineDetector?: OnlineDetector | null to OfflineConfig
  • Modified TransactionExecutor.runExecution() to check online status before processing
  • Added isOnline() check when notifyOnline() is called
  • Added tests
  • Updated README.md

Problem

Currently, TransactionExecutor attempts to execute transactions even when the user is offline, leading to:

  • Unnecessary network calls during offline periods
  • Continuous error throwing until the 10-retry limit is reached
  • Data loss risk: transactions are cleared after ~5 minutes offline (10 retries with exponential backoff)

Solution

This PR introduces configurable online detection to prevent transaction execution when offline:

  1. Enhanced OnlineDetector interface with isOnline() method
  2. Configurable detector in OfflineConfig:
    • undefined (default): uses DefaultOnlineDetector
    • Custom detector: user-provided implementation
  3. Online check before execution: skips transaction processing when offline
  4. network/connectivity errors no longer count toward retry limit

Benefits

  • Prevents data loss during extended offline periods
  • Preserves retry budget for actual failures
  • Auto-resumes execution when notifyOnline() is called
  • Supports custom detection logic (ping endpoint, ...)

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

🦋 Changeset detected

Latest commit: e5b5066

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/offline-transactions Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Toba-bonjour Toba-bonjour force-pushed the toba/skip-transaction-retry-when-offline branch from 1d51bbf to 0a292f5 Compare December 22, 2025 22:20
Toba-bonjour and others added 6 commits December 22, 2025 23:29
…tion when offline

- Add onlineDetector config option to allow custom online detection
- Change onlineDetector type from DefaultOnlineDetector to OnlineDetector interface
- Add isOnline() and dispose() methods to OnlineDetector interface
- Check online status before executing transactions in TransactionExecutor
- Clear scheduler before reloading filtered transactions to ensure consistency
- Pass onlineDetector to TransactionExecutor for status checks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@Toba-bonjour Toba-bonjour force-pushed the toba/skip-transaction-retry-when-offline branch from 0a292f5 to d68bebe Compare December 22, 2025 22:31
@Toba-bonjour Toba-bonjour marked this pull request as ready for review December 24, 2025 11:04
@Toba-bonjour Toba-bonjour changed the title WIP: Expose onlineDetector and add check online status before executing transactions Expose onlineDetector and add check online status before executing transactions Dec 24, 2025
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.

1 participant