Skip to content

Commit

Permalink
Merge pull request #1736 from ably/1732/throw-readable-error-in-verce…
Browse files Browse the repository at this point in the history
…l-edge-runtime

Throw error when instantiating Realtime instances in Vercel Edge runtime
  • Loading branch information
VeskeR authored Apr 16, 2024
2 parents 5911e9a + a307618 commit 8aaa996
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/common/lib/client/baserealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ class BaseRealtime extends BaseClient {
constructor(options?: ClientOptions | string) {
super(Defaults.objectifyOptions(options, false, 'BaseRealtime'));
Logger.logAction(Logger.LOG_MINOR, 'Realtime()', '');

// currently we cannot support using Ably.Realtime instances in Vercel Edge runtime.
// this error can be removed after fixing https://github.com/ably/ably-js/issues/1731,
// and https://github.com/ably/ably-js/issues/1732
// @ts-ignore
if (typeof EdgeRuntime === 'string') {
throw new ErrorInfo(
`Ably.Realtime instance cannot be used in Vercel Edge runtime.` +
` If you are running Vercel Edge functions, please replace your` +
` "new Ably.Realtime()" with "new Ably.Rest()" and use Ably Rest API` +
` instead of the Realtime API. If you are server-rendering your application` +
` in the Vercel Edge runtime, please use the condition "if (typeof EdgeRuntime === 'string')"` +
` to prevent instantiating Ably.Realtime instance during SSR in the Vercel Edge runtime.`,
40000,
400,
);
}

this._additionalTransportImplementations = BaseRealtime.transportImplementationsFromPlugins(this.options.plugins);
this._RealtimePresence = this.options.plugins?.RealtimePresence ?? null;
this.connection = new Connection(this, this.options);
Expand Down

0 comments on commit 8aaa996

Please sign in to comment.