Skip to content

Commit

Permalink
moves prefetching logic away from page generation
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Aug 7, 2024
1 parent 9779fc1 commit 143c472
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/app/(static)/events-news/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import APP_HOSTNAME from '@/lib';

const INITIAL_NEWS_PAGE = 1;

export default async function EventsNews() {
const queryClient = new QueryClient();

const prefetchData = async (queryClient: QueryClient) => {
await queryClient.prefetchQuery({
queryKey: queryKeys.events.past.queryKey,
queryFn: async () => {
Expand All @@ -37,7 +35,7 @@ export default async function EventsNews() {
queryFn: async () => {
try {
const response = await fetch(`${APP_HOSTNAME}/events
`);
`);
if (!response.ok) {
throw new Error('Failed to fetch upcoming events');
}
Expand Down Expand Up @@ -67,6 +65,12 @@ export default async function EventsNews() {
}
},
});
};

export default async function EventsNews() {
const queryClient = new QueryClient();

await prefetchData(queryClient);

return (
<HydrationBoundary state={dehydrate(queryClient)}>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const APP_HOSTNAME = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
export const APP_HOSTNAME = process.env.NEXT_PUBLIC_VERCEL_URL
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
: process.env.NEXT_PUBLIC_HOSTNAME;

export default APP_HOSTNAME;

0 comments on commit 143c472

Please sign in to comment.