Skip to content

Commit 474dd8b

Browse files
committed
fix: remove rq hydrate
Signed-off-by: Innei <[email protected]>
1 parent 4ea3d59 commit 474dd8b

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

src/app/layout.tsx

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import '../styles/index.css'
22

3-
import { dehydrate } from '@tanstack/react-query'
43
import { Analytics } from '@vercel/analytics/react'
54
import { ToastContainer } from 'react-toastify'
6-
import { headers } from 'next/dist/client/components/headers'
75

86
import { ClerkProvider } from '@clerk/nextjs'
97

108
import { appConfig } from '~/app.config'
119
import { Root } from '~/components/layout/root/Root'
12-
import { REQUEST_GEO, REQUEST_PATHNAME } from '~/constants/system'
1310
import { defineMetadata } from '~/lib/define-metadata'
1411
import { sansFont, serifFont } from '~/lib/fonts'
12+
import { AggregationProvider } from '~/providers/root/aggregation-data-provider'
13+
import { queries } from '~/queries/definition'
1514
import { getQueryClient } from '~/utils/query-client.server'
1615

1716
import { Providers } from '../providers/root'
18-
import { Hydrate } from './hydrate'
1917
import { init } from './init'
2018

2119
init()
@@ -88,33 +86,36 @@ export default async function RootLayout(props: Props) {
8886

8987
const queryClient = getQueryClient()
9088

91-
const dehydratedState = dehydrate(queryClient, {
92-
shouldDehydrateQuery: (query) => {
93-
if (query.state.error) return false
94-
if (!query.meta) return true
95-
const {
96-
shouldHydration,
97-
hydrationRoutePath,
98-
skipHydration,
99-
forceHydration,
100-
} = query.meta
101-
102-
if (forceHydration) return true
103-
if (hydrationRoutePath) {
104-
const pathname = headers().get(REQUEST_PATHNAME)
105-
106-
if (pathname === query.meta?.hydrationRoutePath) {
107-
if (!shouldHydration) return true
108-
return (shouldHydration as Function)(query.state.data as any)
109-
}
110-
}
111-
112-
if (skipHydration) return false
113-
114-
return (shouldHydration as Function)?.(query.state.data as any) ?? false
115-
},
89+
// const dehydratedState = dehydrate(queryClient, {
90+
// shouldDehydrateQuery: (query) => {
91+
// if (query.state.error) return false
92+
// if (!query.meta) return true
93+
// const {
94+
// shouldHydration,
95+
// hydrationRoutePath,
96+
// skipHydration,
97+
// forceHydration,
98+
// } = query.meta
99+
100+
// if (forceHydration) return true
101+
// if (hydrationRoutePath) {
102+
// const pathname = headers().get(REQUEST_PATHNAME)
103+
104+
// if (pathname === query.meta?.hydrationRoutePath) {
105+
// if (!shouldHydration) return true
106+
// return (shouldHydration as Function)(query.state.data as any)
107+
// }
108+
// }
109+
110+
// if (skipHydration) return false
111+
112+
// return (shouldHydration as Function)?.(query.state.data as any) ?? false
113+
// },
114+
// })
115+
116+
const data = await queryClient.fetchQuery({
117+
...queries.aggregation.root(),
116118
})
117-
const geo = headers().get(REQUEST_GEO)
118119

119120
return (
120121
// <ClerkProvider localization={ClerkZhCN}>
@@ -124,12 +125,12 @@ export default async function RootLayout(props: Props) {
124125
className={`${sansFont.variable} ${serifFont.variable} m-0 h-full p-0 font-sans`}
125126
>
126127
<Providers>
127-
<Hydrate state={dehydratedState}>
128-
<Root>{children}</Root>
129-
</Hydrate>
128+
<AggregationProvider aggregationData={data} />
129+
{/* <Hydrate state={dehydratedState}> */}
130+
<Root>{children}</Root>
131+
{/* </Hydrate> */}
130132
</Providers>
131133
<ToastContainer />
132-
{!!geo && <div>{geo}</div>}
133134
</body>
134135
</html>
135136
<Analytics />

src/providers/root/aggregation-data-provider.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { useCallback, useEffect, useRef } from 'react'
24
import { atom, useAtomValue } from 'jotai'
35
import { selectAtom } from 'jotai/utils'
@@ -6,23 +8,24 @@ import type { FC, PropsWithChildren } from 'react'
68

79
import { fetchAppUrl } from '~/atoms'
810
import { login } from '~/atoms/owner'
9-
import { useAggregationQuery } from '~/hooks/data/use-aggregation'
1011
import { jotaiStore } from '~/lib/store'
1112

1213
export const aggregationDataAtom = atom<null | AggregateRoot>(null)
1314

14-
export const AggregationProvider: FC<PropsWithChildren> = ({ children }) => {
15-
const { data } = useAggregationQuery()
16-
15+
export const AggregationProvider: FC<
16+
PropsWithChildren<{
17+
aggregationData: AggregateRoot
18+
}>
19+
> = ({ children, aggregationData }) => {
1720
useEffect(() => {
18-
if (!data) return
19-
jotaiStore.set(aggregationDataAtom, data)
20-
}, [data])
21+
if (!aggregationData) return
22+
jotaiStore.set(aggregationDataAtom, aggregationData)
23+
}, [aggregationData])
2124

2225
const callOnceRef = useRef(false)
2326
useEffect(() => {
2427
if (callOnceRef.current) return
25-
if (!data?.user) return
28+
if (!aggregationData?.user) return
2629
callOnceRef.current = true
2730
login().then((logged) => {
2831
if (logged) {
@@ -32,7 +35,7 @@ export const AggregationProvider: FC<PropsWithChildren> = ({ children }) => {
3235
}, 1000)
3336
}
3437
})
35-
}, [data?.user])
38+
}, [aggregationData?.user])
3639

3740
return children
3841
}

src/providers/root/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ThemeProvider } from 'next-themes'
66
import type { PropsWithChildren } from 'react'
77

88
import { ProviderComposer } from '../../components/common/ProviderComposer'
9-
import { AggregationProvider } from './aggregation-data-provider'
109
import { DebugProvider } from './debug-provider'
1110
import { EventProvider } from './event-provider'
1211
import { JotaiStoreProvider } from './jotai-provider'
@@ -20,7 +19,7 @@ const contexts: JSX.Element[] = [
2019
<ThemeProvider key="themeProvider" />,
2120
<ReactQueryProvider key="reactQueryProvider" />,
2221
<JotaiStoreProvider key="jotaiStoreProvider" />,
23-
<AggregationProvider key="aggregationProvider" />,
22+
2423
<EventProvider key="viewportProvider" />,
2524

2625
<PageScrollInfoProvider key="PageScrollInfoProvider" />,

0 commit comments

Comments
 (0)