Skip to content

feat: debounce_timing [rn]#28

Merged
choudlet merged 9 commits into
mainfrom
chrish/sc-37711/react-native-network-reachability
Apr 10, 2026
Merged

feat: debounce_timing [rn]#28
choudlet merged 9 commits 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

  • Added DebouncedNetworkMonitor to debounce online transitions

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
  • Existing offline→online test updated for debounce timing
  • All 190 tests pass (zero regressions)

choudlet and others added 6 commits April 7, 2026 19:58
Add network connectivity awareness to the React Native SDK so
events queue in memory while offline and flush on reconnect.

- NetworkMonitor TS wrapper + native bridge modules
  (iOS NWPathMonitor, Android ConnectivityManager)
- CircuitBreaker.reset() clears stale backoff on reconnect
- Dispatcher guards flush with isNetworkAvailable()
- MetaRouterAnalyticsClient wires network monitor via DI
- Add maxOfflineDiskEvents to InitOptions (for PR 2)
- Comprehensive tests for all new behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Online transitions are debounced by 2s to prevent circuit breaker
resets, wasteful flushes, and churn during rapid network flapping.
Offline transitions remain immediate. networkStatus stays 'disconnected'
during the debounce window so the dispatcher's isNetworkAvailable()
continues to block flush attempts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@choudlet choudlet changed the base branch from chrish/sc-36910/story-network-reachability-awareness to main April 10, 2026 16:54
Copy link
Copy Markdown
Collaborator

@brandon-metarouter brandon-metarouter left a comment

Choose a reason for hiding this comment

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

Left some take it or leave it comments!

Comment thread src/analytics/utils/networkMonitor.ts Outdated
err
);
.catch(() => {
/* fallback: stay connected */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just checking if log removal is intended.

Comment thread src/analytics/utils/networkMonitor.ts Outdated
err
);
} catch {
// Native module not available — stay as always-connected (default behavior)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here, just double checking log removal.

@@ -0,0 +1,73 @@
import type { NetworkReachability, NetworkStatus } from './networkMonitor';

const DEBOUNCE_MS = 2_000;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this is only used in DebouncedNetworkMonitor, maybe a class const instead? Something like private static readonly DEBOUNCE_MS = 2_000; ?

expect(stopSpy).toHaveBeenCalled();
});

it('online transition is debounced — rapid flapping produces single flush', async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good test!

@choudlet choudlet merged commit da6b846 into main Apr 10, 2026
2 checks passed
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