Skip to content

feat: debounce_timing [rn]#27

Closed
choudlet wants to merge 1 commit into
mainfrom
chrish/sc-37711/react-native-network-reachability
Closed

feat: debounce_timing [rn]#27
choudlet wants to merge 1 commit into
mainfrom
chrish/sc-37711/react-native-network-reachability

Conversation

@choudlet
Copy link
Copy Markdown
Collaborator

@choudlet choudlet commented Apr 9, 2026

Summary

Adds 2-second debouncing to network reachability online transitions. Offline transitions remain immediate. This prevents circuit breaker resets, wasteful flushes, and churn during rapid network flapping (e.g., tunnel, elevator, weak cell signal).

Ticket: SC-37711

Changes

  • src/analytics/network/NetworkReachability.ts — New NetworkStatus type and NetworkReachability interface for network monitoring abstraction
  • src/analytics/network/StubNetworkMonitor.ts — Test double with simulate() for synchronous status changes (no internal timers)
  • src/analytics/dispatcher.ts — Added resetCircuitBreaker() method for post-reconnect circuit reset
  • src/analytics/MetaRouterAnalyticsClient.tsONLINE_DEBOUNCE_MS (2s) constant, AnalyticsClientDeps DI interface, debounced onStatusChange callback in setupNetworkMonitor(), cleanup in reset(), network-aware canSend() and getDebugInfo()

Behavioral contract (cross-platform)

Transition Debounced? Side-effects
connected → disconnected No (immediate) Cancel debounce timer, update networkStatus, dispatcher sees offline via canSend()
disconnected → connected Yes (2s) After 2s stable: update networkStatus, reset circuit breaker, flush
Rapid flap ending offline No Single offline, zero online events
Rapid flap ending online Yes (2s from last) Timer resets each cycle; only final stable connected triggers flush

During the 2s debounce window, canSend() returns false so periodic/threshold flushes are blocked.

Public API

No changes. Entirely internal. No new config options or methods. The AnalyticsClientDeps second constructor arg is optional and only used for DI in tests.

Test plan

  • Rapid flapping produces single flush (not one per transition)
  • Debounce timer cancelled when device goes back offline
  • Clean online transition flushes after exactly 2s
  • Offline transition is immediate (not debounced)
  • reset() cancels pending debounce timer
  • Default connected status when no monitor is provided
  • All 168 existing tests pass (zero regressions)

🤖 Generated with Claude Code

Online transitions are debounced by 2s to prevent churn from rapid
network flapping. Offline transitions remain immediate. The debounce
lives in MetaRouterAnalyticsClient's onStatusChange callback, keeping
NetworkReachability/StubNetworkMonitor as low-level fire-on-every-
transition abstractions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@choudlet
Copy link
Copy Markdown
Collaborator Author

choudlet commented Apr 9, 2026

Closing — rebasing debounce work onto the network reachability infrastructure branch instead.

@choudlet choudlet closed this Apr 9, 2026
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