Skip to content

react: add error states and onError callbacks to hooks#58

Open
ttypic wants to merge 2 commits intomainfrom
error-handling
Open

react: add error states and onError callbacks to hooks#58
ttypic wants to merge 2 commits intomainfrom
error-handling

Conversation

@ttypic
Copy link
Copy Markdown
Contributor

@ttypic ttypic commented Apr 16, 2026

useClientTransport now returns { transport, transportError } instead of throwing when no provider is found or when createClientTransport throws. A new onError option subscribes to post-construction transport errors via transport.on('error', ...) with automatic cleanup on unmount.

useView adds an error field to ViewHandle set when loadOlder fails and cleared on the next successful load.

TransportSlot replaces the raw transport in TransportContext holding { transport, error }. TransportProvider wraps createClientTransport in try/catch so construction errors surface as transportError in useClientTransport rather than crashing the tree.

Tests cover missing provider, construction failure, onError subscription and cleanup, loadOlder error/clear cycle

Changed `TransportProvider` to schedule the transport close as a microtask on unmount, ensuring React's Strict Mode remount cycle cancels the close during development. Updated corresponding test to verify behavior.
@github-actions github-actions bot temporarily deployed to staging/pull/58/typedoc April 16, 2026 12:15 Inactive
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 92.77% 2119 / 2284
🔵 Statements 91.11% 2265 / 2486
🔵 Functions 93.26% 388 / 416
🔵 Branches 78.2% 965 / 1234
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/react/create-transport-hooks.ts 37.5% 8.33% 28.57% 28.57% 139-143
src/react/use-ably-messages.ts 100% 85.71% 100% 100%
src/react/use-active-turns.ts 100% 90.9% 100% 100%
src/react/use-client-transport.ts 90.9% 94.73% 80% 90.62% 43, 49, 180-183
src/react/use-create-view.ts 100% 85.71% 100% 100%
src/react/use-send.ts 100% 85.71% 100% 100%
src/react/use-tree.ts 100% 100% 100% 100%
src/react/use-view.ts 81.69% 68.42% 61.11% 85.24% 160, 165, 167, 169, 171, 177, 185-187, 194-196, 204
src/react/contexts/transport-context.ts 100% 100% 100% 100%
src/react/contexts/transport-provider.tsx 94.59% 75% 100% 100% 60, 87
Generated in workflow #148 for commit 68ddb7a by the Vitest Coverage Report Action

useClientTransport now returns { transport, transportError } instead of
throwing when no provider is found or when createClientTransport throws.
A new onError option subscribes to post-construction transport errors
via transport.on('error', ...) with automatic cleanup on unmount.

useView adds an error field to ViewHandle set when loadOlder fails and
cleared on the next successful load. useSend switches to an options-based
API ({ view?, onError? }) with context-fallback view resolution and an
onError callback that fires before re-throwing.

TransportSlot replaces the raw transport in both TransportContext and
NearestTransportContext, holding { transport, error }. TransportProvider
wraps createClientTransport in try/catch so construction errors surface
as transportError in useClientTransport rather than crashing the tree.

Tests cover missing provider, construction failure, onError subscription
and cleanup, loadOlder error/clear cycle, and useSend context fallback.
Base automatically changed from fix-react-dev-double-unmount to main April 16, 2026 13:50
@ttypic ttypic requested review from VeskeR and mschristensen April 16, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant