Skip to content

Commit

Permalink
Reorder chat context and connection wrapper
Browse files Browse the repository at this point in the history
To re-enable dynamic for connection wrapper (otherwise, we need
walletconnect_project_id env var also defined in GitHub for build phase).
  • Loading branch information
kahkeng committed Jul 14, 2023
1 parent d093dc9 commit e6a22ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/contexts/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useQueryClient } from 'react-query';
import useWebSocket, { ReadyState } from 'react-use-websocket';
import { JsonValue } from 'react-use-websocket/dist/lib/types';
import { useRouter } from 'next/router';
import { useSession } from 'next-auth/react';
import { getBackendWebsocketUrl } from '@/utils/backend';

export type Message = {
Expand Down Expand Up @@ -77,10 +76,8 @@ export const ChatContextProvider = ({ children }: { children: ReactNode }) => {
const [connectionStatus, setConnectionStatus] = useState<ReadyState>(ReadyState.UNINSTANTIATED);
const [lastInitSessionId, setLastInitSessionId] = useState<string | null>(null);

const { status } = useSession();
const queryClient = useQueryClient();

//const shouldConnect = status === 'authenticated';
const shouldConnect = true; // allow logged out to view public sessions
const backendUrl = getBackendWebsocketUrl();
const {
Expand Down
22 changes: 10 additions & 12 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import { Session } from 'next-auth';
import Layout from '@/components/experimental_/layout/Layout';

/*
// disabled dynamic because this causes the query.id useEffect hook to fire twice
const ChatContextDynamic = dynamic(() => import('@/contexts/ChatContext'), {
ssr: false,
});
*/
import ChatContextDynamic from '@/contexts/ChatContext';
import ChatContext from '@/contexts/ChatContext';
import { SettingsProvider } from '@/contexts/SettingsContext';
import '@/styles/globals.css';

/*
const ConnectionWrapperDynamic = dynamic(() => import('@/contexts/ConnectionWrapper'), {
ssr: false,
});
*/
import ConnectionWrapperDynamic from '@/contexts/ConnectionWrapper';
import { SettingsProvider } from '@/contexts/SettingsContext';
import '@/styles/globals.css';

const queryClient = new QueryClient();

Expand All @@ -48,15 +46,15 @@ export default function App({
theme="light"
/>
<QueryClientProvider client={queryClient}>
<ConnectionWrapperDynamic session={session}>
<CenterProvider apiKey={process.env.NEXT_PUBLIC_CENTER_APP_KEY}>
<ChatContextDynamic>
<ChatContext>
<ConnectionWrapperDynamic session={session}>
<CenterProvider apiKey={process.env.NEXT_PUBLIC_CENTER_APP_KEY}>
<Layout>
<Component {...pageProps} />
</Layout>
</ChatContextDynamic>
</CenterProvider>
</ConnectionWrapperDynamic>
</CenterProvider>
</ConnectionWrapperDynamic>
</ChatContext>
</QueryClientProvider>
</SettingsProvider>
);
Expand Down

0 comments on commit e6a22ce

Please sign in to comment.