Skip to content

Commit 043ba1e

Browse files
committed
fix: use dynamic import for ably provider
1 parent 01c0342 commit 043ba1e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/app/components/realtime.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Realtime } from 'ably'
2+
import { AblyProvider } from 'ably/react'
3+
import { name } from 'package.json'
4+
import React from 'react'
5+
6+
import { env } from '@/env.mjs'
7+
8+
interface RealtimeProviderProps {
9+
children: React.ReactNode
10+
}
11+
12+
export default function RealtimeProvider({ children }: RealtimeProviderProps) {
13+
const ablyClient = new Realtime({
14+
authUrl: env.NEXT_PUBLIC_ABLY_BASE_URL + '/api/ably',
15+
authMethod: 'POST',
16+
clientId: name,
17+
logLevel: 1,
18+
})
19+
20+
return <AblyProvider client={ablyClient}>{children}</AblyProvider>
21+
}

src/app/providers.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
44
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
5-
import * as Ably from 'ably'
6-
import { AblyProvider, ChannelProvider } from 'ably/react'
5+
import { ChannelProvider } from 'ably/react'
6+
import dynamic from 'next/dynamic'
77
import { Session } from 'next-auth'
88
import { SessionProvider } from 'next-auth/react'
99
import PlausibleProvider from 'next-plausible'
1010
import { ThemeProvider } from 'next-themes'
1111
import * as React from 'react'
1212

13-
import { env } from '@/env.mjs'
13+
const RealtimeProvider = dynamic(() => import('./components/realtime'), {
14+
ssr: false,
15+
})
1416

1517
export interface ProvidersProps {
1618
children: React.ReactNode
1719
session: Session | null
1820
}
1921

2022
const queryClient = new QueryClient()
21-
const ablyClient = new Ably.Realtime({
22-
authUrl: env.NEXT_PUBLIC_ABLY_BASE_URL + '/api/ably',
23-
authMethod: 'POST',
24-
})
2523

2624
export function Providers({ children, session }: ProvidersProps) {
2725
return (
@@ -36,11 +34,11 @@ export function Providers({ children, session }: ProvidersProps) {
3634
enableSystem={true}
3735
>
3836
<QueryClientProvider client={queryClient}>
39-
<AblyProvider client={ablyClient}>
37+
<RealtimeProvider>
4038
<ChannelProvider channelName='retrospective'>
4139
{children}
4240
</ChannelProvider>
43-
</AblyProvider>
41+
</RealtimeProvider>
4442
<ReactQueryDevtools initialIsOpen={false} />
4543
</QueryClientProvider>
4644
</ThemeProvider>

0 commit comments

Comments
 (0)