Problem Statement / Feature Objective
Uncaught React errors, WebSocket connection drops, and API 5xx responses are reported to Sentry but lost when the device is offline. Errors also trigger repetitive alerts for transient failures. A Sentry error boundary must queue errors locally during offline periods and replays them on connectivity restore, with network-aware deduplication and backoff.
Technical Invariants & Bounds
- Offline queue capacity: 500 error records before LRU eviction
- Retry backoff: exponential, starting at 1 s, doubling, max 60 s, reset after 10 min of uptime
- Deduplication window: same error + same component + same hash within 5 seconds → merge with counter
- Max retry attempts per error: 5; after that, drop silently (no infinite retry)
- Queue persisted in IndexedDB under store
sentry/offlineQueue
Codebase Navigation Guide
src/lib/sentry/sentryClient.ts — current Sentry.init() and captureException wrapper
src/components/error/AppErrorBoundary.tsx — existing React error boundary
src/hooks/useNetworkStatus.ts — existing hook exposing navigator.onLine + online/offline events
src/lib/storage/idb.ts — IndexedDB helper for persistence
src/pages/_app.tsx (or equivalent root) — where Sentry.init is called
Implementation Blueprint
- Extend
src/lib/sentry/sentryClient.ts with enqueueError(error, context) that checks navigator.onLine. If offline, stores the error in IndexedDB under sentry/offlineQueue with { timestamp, errorHash, componentStack, count: 1 }. If online, calls Sentry.captureException immediately.
- Create
processOfflineQueue() function that reads all queued errors, attempts Sentry.captureException for each, and deletes them on success. On failure, increments retry count and re-stores with updated backoff timestamp.
- In
AppErrorBoundary.tsx, override componentDidCatch to call enqueueError instead of directly calling Sentry. Render a fallback UI with a "Retry" button and an indicator of queued errors.
- Subscribe to
useNetworkStatuss
Problem Statement / Feature Objective
Uncaught React errors, WebSocket connection drops, and API 5xx responses are reported to Sentry but lost when the device is offline. Errors also trigger repetitive alerts for transient failures. A Sentry error boundary must queue errors locally during offline periods and replays them on connectivity restore, with network-aware deduplication and backoff.
Technical Invariants & Bounds
sentry/offlineQueueCodebase Navigation Guide
src/lib/sentry/sentryClient.ts— currentSentry.init()andcaptureExceptionwrappersrc/components/error/AppErrorBoundary.tsx— existing React error boundarysrc/hooks/useNetworkStatus.ts— existing hook exposingnavigator.onLine+online/offlineeventssrc/lib/storage/idb.ts— IndexedDB helper for persistencesrc/pages/_app.tsx(or equivalent root) — whereSentry.initis calledImplementation Blueprint
src/lib/sentry/sentryClient.tswithenqueueError(error, context)that checksnavigator.onLine. If offline, stores the error in IndexedDB undersentry/offlineQueuewith{ timestamp, errorHash, componentStack, count: 1 }. If online, callsSentry.captureExceptionimmediately.processOfflineQueue()function that reads all queued errors, attemptsSentry.captureExceptionfor each, and deletes them on success. On failure, increments retry count and re-stores with updated backoff timestamp.AppErrorBoundary.tsx, overridecomponentDidCatchto callenqueueErrorinstead of directly calling Sentry. Render a fallback UI with a "Retry" button and an indicator of queued errors.useNetworkStatuss