From 918106443cff127d25058c4eb2a0e8b486f29cf8 Mon Sep 17 00:00:00 2001 From: Owen Pearson Date: Mon, 25 Sep 2023 10:40:58 +0100 Subject: [PATCH] fix: throw descriptive error when callbacks used with react --- src/platform/react-hooks/src/AblyProvider.tsx | 4 ++++ src/platform/react-hooks/src/fakes/ably.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/src/platform/react-hooks/src/AblyProvider.tsx b/src/platform/react-hooks/src/AblyProvider.tsx index 477e58d8ed..6382c8060e 100644 --- a/src/platform/react-hooks/src/AblyProvider.tsx +++ b/src/platform/react-hooks/src/AblyProvider.tsx @@ -35,6 +35,10 @@ export const AblyProvider = ({ client, children, id = 'default' }: AblyProviderP throw new Error('AblyProvider: the `client` prop is required'); } + if (!(client instanceof Ably.Realtime) && !client?.options?.promises) { + throw new Error('AblyProvider: the `client` prop must take an instance of Ably.Realtime.Promise'); + } + const realtime = useMemo(() => client, [client]); let context = getContext(id); diff --git a/src/platform/react-hooks/src/fakes/ably.ts b/src/platform/react-hooks/src/fakes/ably.ts index c4bb821c9c..a94cf735f1 100644 --- a/src/platform/react-hooks/src/fakes/ably.ts +++ b/src/platform/react-hooks/src/fakes/ably.ts @@ -4,6 +4,7 @@ export class FakeAblySdk { public clientId: string; public channels: ClientChannelsCollection; public connection: Connection; + public options = { promises: true }; constructor() { this.clientId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);