react-realtime-hooks 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Demo](https://img.shields.io/github/actions/workflow/status/volkov85/react-realtime-hooks/pages.yml?branch=main&label=demo)](https://github.com/volkov85/react-realtime-hooks/actions/workflows/pages.yml)
6
6
  [![license](https://img.shields.io/npm/l/react-realtime-hooks)](https://github.com/volkov85/react-realtime-hooks/blob/main/LICENSE)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-typed-3178c6)](https://www.typescriptlang.org/)
8
- [![react](https://img.shields.io/badge/react-19.x-149eca)](https://www.npmjs.com/package/react)
8
+ [![react](https://img.shields.io/badge/react-19.2%2B-149eca)](https://www.npmjs.com/package/react)
9
9
 
10
10
  Production-ready React hooks for WebSocket and SSE with auto-reconnect, heartbeat, typed connection state, and browser network awareness including page visibility and connection gating.
11
11
 
@@ -62,7 +62,7 @@ npm install react-realtime-hooks
62
62
 
63
63
  Peer dependency:
64
64
 
65
- - `react@^19.0.0`
65
+ - `react@^19.2.0`
66
66
 
67
67
  ## How It Feels
68
68
 
@@ -419,7 +419,7 @@ export function GatedNotifications() {
419
419
  | `lastMessage` | `TIncoming \| null` | Last parsed message |
420
420
  | `lastMessageEvent` | `MessageEvent \| null` | Last raw message event |
421
421
  | `lastCloseEvent` | `CloseEvent \| null` | Last close event |
422
- | `lastError` | `Event \| null` | Last error |
422
+ | `lastError` | `Event \| null` | Last transport error, or `RealtimeErrorEvent` for parse/heartbeat failures |
423
423
  | `bufferedAmount` | `number` | Current socket buffer size |
424
424
  | `reconnectState` | reconnect snapshot or `null` | Current reconnect data |
425
425
  | `heartbeatState` | heartbeat snapshot or `null` | Current heartbeat data |
@@ -432,6 +432,10 @@ When you configure `useWebSocket` heartbeat, you can also set `timeoutAction` an
432
432
  `errorAction` to `"none"`, `"close"`, or `"reconnect"`. The default is
433
433
  `"reconnect"` when reconnect is enabled and `"close"` otherwise.
434
434
 
435
+ When parsing or heartbeat execution fails, `onError` receives a
436
+ `RealtimeErrorEvent` with `kind` and `cause` so the original thrown value is not
437
+ lost.
438
+
435
439
  </details>
436
440
 
437
441
  <details>
@@ -462,12 +466,17 @@ When you configure `useWebSocket` heartbeat, you can also set `timeoutAction` an
462
466
  | `lastEventName` | `string \| null` | Last SSE event name |
463
467
  | `lastMessage` | `TMessage \| null` | Last parsed payload |
464
468
  | `lastMessageEvent` | `MessageEvent \| null` | Last raw message event |
465
- | `lastError` | `Event \| null` | Last error |
469
+ | `lastError` | `Event \| null` | Last transport error, or `RealtimeErrorEvent` for parse failures |
466
470
  | `reconnectState` | reconnect snapshot or `null` | Current reconnect data |
467
471
  | `open` | `() => void` | Manual connect |
468
472
  | `close` | `() => void` | Manual close |
469
473
  | `reconnect` | `() => void` | Manual reconnect |
470
474
 
475
+ On `EventSource` errors, the hook closes the current native source and schedules
476
+ the next connection through `useReconnect`. That makes SSE retries use the
477
+ configured backoff, jitter, and attempt limits instead of the browser's built-in
478
+ retry loop.
479
+
471
480
  </details>
472
481
 
473
482
  <details>
@@ -623,7 +632,7 @@ That keeps the gate predictable when multiple blockers apply at once.
623
632
 
624
633
  - `useEventSource` is receive-only by design. SSE is not a bidirectional transport.
625
634
  - `useWebSocket` heartbeat support is client-side. You still define your own server ping/pong protocol.
626
- - If `parseMessage` throws, the hook calls `onError`, closes the current transport, moves into `error`, stores `lastError`, and stops auto-reconnect until manual `open()` or `reconnect()`.
635
+ - If `parseMessage` throws, the hook calls `onError` with `RealtimeErrorEvent`, closes the current transport, moves into `error`, stores `lastError`, and stops auto-reconnect until manual `open()` or `reconnect()`.
627
636
  - Stopping heartbeat clears timeout state and the previous beat/ack timestamps so a new session starts with fresh metrics.
628
637
  - `connect: false` keeps the hook in `idle` until `open()` is called.
629
638
  - Manual `close()` is sticky. The hook stays closed until `open()` or `reconnect()` is called.