-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
Description
Describe the bug
This issue is very similar to this one: #1661
To Reproduce
- Next.js + ReactQuery + GraphQL + TypeScript + GraphQL codegen
- My Code:
[pages/_app.tsx]
class MyApp extends App<AppProps> {
queryClient: QueryClient | null = null
constructor(props) {
super(props)
this.queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
refetchOnMount: false,
cacheTime: 1000 * 60 * 100,
retryDelay: 1000 * 5,
staleTime: 1000 * 60 * 10,
},
},
})
}
static async getInitialProps(appContext: AppContext) {
return await appGetInitialProps({
appContext,
redirectRoute: ROUTES.main.index,
isPrivatePath: () => false,
})
}
render() {
const { pageProps, Component } = this.props
console.log('pageProps', pageProps.dehydratedState)
return (
<WithProviders store={store} dialogVariants={dialogVariants}>
<QueryClientProvider client={this.queryClient}>
<Hydrate state={pageProps.dehydratedState}>
<MainLayout>
<Component {...pageProps} />
</MainLayout>
</Hydrate>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</WithProviders>
)
}
}
[pages/index.tsx]
export const _getHomepageArticles = fetcher<
GetHomepageArticlesQuery,
GetHomepageArticlesQueryVariables
>(GetHomepageArticlesDocument)
export const useGetHomepageArticlesQuery = <
TData = GetHomepageArticlesQuery,
TError = unknown
>(
variables?: GetHomepageArticlesQueryVariables,
options?: UseQueryOptions<GetHomepageArticlesQuery, TError, TData>,
) =>
useQuery<GetHomepageArticlesQuery, TError, TData>(
['getHomepageArticles', variables],
_getHomepageArticles,
options,
)
const Index = () => {
const { data, ...other } = useGetHomepageArticlesQuery()
console.log('Index Page:', data, 'params:', other)
return <IndexPage />
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const queryClient = new QueryClient()
await queryClient.prefetchQuery('getHomepageArticles', _getHomepageArticles)
console.log('Result Cache:', queryClient.getQueryCache())
return {
props: {
dehydratedState: dehydrate(queryClient),
},
}
}
Expected behavior
useGetHomepageArticlesQuery should return filled in data param.
Current behavior
useGetHomepageArticlesQuery returns data = undefined and isFetching = true (data is being loaded at the client = preloaded state is being ignored).
Logs Screenshot
Desktop:
- OS: MacOS M1
- Browser: Chrome
- RQ Version: Tried latest and
3.5.13from the issue above.
GZLiew
