Skip to content

Commit

Permalink
Make email API call from client only.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoVink committed Jan 7, 2025
1 parent 3ab0b03 commit 74cf859
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion web/app/(main)/emails/components-client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { format, formatDistanceToNow } from 'date-fns';

import { ThreadEntriesSkeleton, Card, ThreadEntryScrollContainer } from './components-server';
import { useApiCall, useTextApiCall } from '@/lib/api';
import ClientOnly from '@/components/clientonly';

import './email.css';

Expand Down Expand Up @@ -117,7 +118,7 @@ export const ThreadEntries = () => {
const searchParams = useSearchParams();
const threadId = searchParams.get('id');
const result = threadId
? <ThreadEntriesFetch threadId={threadId} />
? <ClientOnly><ThreadEntriesFetch threadId={threadId} /></ClientOnly>
: <ThreadEntriesSkeleton />;

return result;
Expand Down
13 changes: 5 additions & 8 deletions web/app/(main)/emails/components-server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,11 @@ export const ThreadEntriesSkeleton = () => (
);


export const ThreadEntriesSuspenseContainer = async ({ threadId }) => {
const session = await auth();
return (
<Suspense key={threadId} fallback={<ThreadEntriesSkeleton />}>
<ThreadEntries userId={session.user.id} />
</Suspense>
);
}
export const ThreadEntriesSuspenseContainer = ({ threadId }) => (
<Suspense key={threadId} fallback={<ThreadEntriesSkeleton />}>
<ThreadEntries />
</Suspense>
);


export const Layout = ({ listComponent, detailComponent }) => (
Expand Down
10 changes: 10 additions & 0 deletions web/components/clientonly.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dynamic from 'next/dynamic';

const ClientOnly = (props) => {
const { children } = props;
return children;
};

export default dynamic(() => Promise.resolve(ClientOnly), {
ssr: false,
});

0 comments on commit 74cf859

Please sign in to comment.