Repository navigation
Throw a descriptive error when React hooks are used outside an AblyProvider - #2316
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe hooks now handle missing Ably context entries with an explicit provider error instead of accessing fields on an absent entry. Tests cover calls outside an ChangesReact hook context errors
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
-
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title check ✅ Passed The title clearly and concisely describes the main change: descriptive errors when React hooks run outside an AblyProvider. Linked Issues check ✅ Passed Issue #1849requires a descriptive error when hooks run outside an . The PR changes useAbly.ts and useChannelInstance.ts to check for a missing context entry and throw the exact required…Out of Scope Changes check ✅ Passed The PR changes only the affected hook error handling and adds focused tests for the linked issue behavior. The changes support Issue #1849and show no unrelated implementation.
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the context with care
No provider? The right error is there
A missing ID joins the test
Each hook reports the expected
Then hops through the meadow with flair
Comment @coderabbitai help to get the list of available commands.
ttypic
left a comment
There was a problem hiding this comment.
LGTM, thanks for contribution
7d076bc to
4607350
Compare
Fixes #1849
Summary
Calling
useAbly,useChannelorusePresenceoutside an<AblyProvider>throws aCannot read properties of undefinedTypeError, which does not point to the cause. The hooks now throwCould not find ably client in context. Make sure your ably hooks are called inside an <AblyProvider>.useAblychecks the context value before it returns the client.useChannelInstancechecks the context value before it reads the channel state from it. The same message covers the case where you pass anablyIdthat has no matching provider.Testing
Adds
src/platform/react-hooks/src/hooks/useAbly.test.tsxwith four cases:useAbly,useChannelandusePresenceoutside a provider, anduseAblywith an unknownablyId.Summary by CodeRabbit
AblyProvideror with an unconfigured client, rather than failing while accessing missing context.