Skip to content

Commit

Permalink
fix: remove fuck unstable_cache
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Feb 23, 2024
1 parent 7012092 commit c5c7f23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/app/(app)/(home)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { dehydrate } from '@tanstack/react-query'
import type { PropsWithChildren } from 'react'

import { QueryHydrate } from '~/components/common/QueryHydrate'
import { getOrSetCache } from '~/lib/cache'
import { onlyGetOrSetCacheInVercelButFallback } from '~/lib/cache'
import { isShallowEqualArray } from '~/lib/lodash'
import { getQueryClient } from '~/lib/query-client.server'
import { apiClient } from '~/lib/request'
Expand All @@ -18,7 +18,7 @@ export default async function HomeLayout(props: PropsWithChildren) {
.fetchQuery({
queryKey,
queryFn: async () => {
return getOrSetCache(
return onlyGetOrSetCacheInVercelButFallback(
'aggregate-top',
async () => {
return (await apiClient.aggregate.getTop(5)).$serialized
Expand Down
30 changes: 13 additions & 17 deletions src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cache } from 'react'
import { ToastContainer } from 'react-toastify'
import { unstable_cache } from 'next/cache'
import type { Viewport } from 'next'
import type { PropsWithChildren } from 'react'

Expand All @@ -14,7 +14,7 @@ import { AccentColorStyleInjector } from '~/components/modules/shared/AccentColo
import { SearchPanelWithHotKey } from '~/components/modules/shared/SearchFAB'
import { TocAutoScroll } from '~/components/modules/toc/TocAutoScroll'
import { attachUAAndRealIp } from '~/lib/attach-ua'
import { getOrSetCache } from '~/lib/cache'
import { onlyGetOrSetCacheInVercelButFallback } from '~/lib/cache'
import { sansFont, serifFont } from '~/lib/fonts'
import { getQueryClient } from '~/lib/query-client.server'
import { AggregationProvider } from '~/providers/root/aggregation-data-provider'
Expand Down Expand Up @@ -43,23 +43,19 @@ export function generateViewport(): Viewport {
}

const key = 'root-data'
const fetchAggregationData = unstable_cache(
async () => {
const queryClient = getQueryClient()
const fetchAggregationData = cache(async () => {
const queryClient = getQueryClient()

return getOrSetCache(
key,
async () => {
attachUAAndRealIp()
return onlyGetOrSetCacheInVercelButFallback(
key,
async () => {
attachUAAndRealIp()

return queryClient.fetchQuery(queries.aggregation.root())
},
revalidate,
)
},
[key],
{ revalidate },
)
return queryClient.fetchQuery(queries.aggregation.root())
},
revalidate,
)
})
export const generateMetadata = async () => {
const fetchedData = await fetchAggregationData()

Expand Down

0 comments on commit c5c7f23

Please sign in to comment.