-
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
1 changed file
with
21 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import { dehydrate } from '@tanstack/react-query' | ||
import type { PropsWithChildren } from 'react' | ||
|
||
import { QueryHydrate } from '~/components/common/QueryHydrate' | ||
import { isShallowEqualArray } from '~/lib/lodash' | ||
import { getQueryClient } from '~/lib/query-client.server' | ||
import { apiClient } from '~/lib/request' | ||
import { requestErrorHandler } from '~/lib/request.server' | ||
import { definePrerenderPage, requestErrorHandler } from '~/lib/request.server' | ||
|
||
import { queryKey } from './query' | ||
|
||
export const dynamic = 'force-dynamic' | ||
export const revalidate = 3600 | ||
export default definePrerenderPage()({ | ||
fetcher() { | ||
const queryClient = getQueryClient() | ||
return queryClient | ||
.fetchQuery({ | ||
queryKey, | ||
queryFn: async () => { | ||
return (await apiClient.aggregate.getTop(5)).$serialized | ||
}, | ||
}) | ||
.catch(requestErrorHandler) | ||
}, | ||
async Component(props) { | ||
const queryClient = getQueryClient() | ||
|
||
export default async function HomeLayout(props: PropsWithChildren) { | ||
const queryClient = getQueryClient() | ||
await queryClient | ||
.fetchQuery({ | ||
queryKey, | ||
queryFn: async () => { | ||
return (await apiClient.aggregate.getTop(5)).$serialized | ||
const dehydrateState = dehydrate(queryClient, { | ||
shouldDehydrateQuery(query) { | ||
return isShallowEqualArray(query.queryKey as any, queryKey) | ||
}, | ||
}) | ||
.catch(requestErrorHandler) | ||
|
||
const dehydrateState = dehydrate(queryClient, { | ||
shouldDehydrateQuery(query) { | ||
return isShallowEqualArray(query.queryKey as any, queryKey) | ||
}, | ||
}) | ||
return <QueryHydrate state={dehydrateState}>{props.children}</QueryHydrate> | ||
} | ||
return <QueryHydrate state={dehydrateState}>{props.children}</QueryHydrate> | ||
}, | ||
}) |