-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work out of the box with next 13 #4933
Comments
sdkmanager --uninstall --package_file #4939 |
With Next.js 13's 'use client';
import { QueryClient, QueryClientProvider } from 'react-query'
const queryClient = new QueryClient()
export default function QueryProvider({
children,
}: {
children: React.ReactNode
}) {
return (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);
} export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
{/*
<head /> will contain the components returned by the nearest parent
head.tsx. Find out more at https://beta.nextjs.org/docs/api-reference/file-conventions/head
*/}
<head />
<body>
<QueryProvider>
{children}
</QueryProvider>
</body>
</html>
)
} See Using context in Client Components for more details. |
I am seeing the same error. The TanStack docs suggest creating a singleton client on the server for import into server components, but that does not seem to work. I do not get the error with the |
+1 have the same error after attempt to follow TanStack docs |
I also cannot get it working with Hydrate, following the docs. It does work with the I made a sandbox with a very simple Next 13 app. I made two examples, one with initial data, and one with hydrate, by following the TanStack docs for Next 13. The hydrate code throws the error. |
The docs say you have to put the providers into a separate |
Yes, it works up to now but once you start using getQueryClient in server component you get the error |
@Ephem do you know why this is happening? It seems like
|
@TkDodo If you go to the Hydrate.esm.js output the |
Can't upload img... module path: line 1: source code path: |
I think it could be this: probably we'd need to preserve the directive for esm builds? |
The way suggested will add |
We have added I'm gonna wait for some input from @Ephem if that's correct or not. |
Busy days so will look at this in more detail soon, but I think you've definitely found the cause. Will need to think a bit on how this affects the different builds, can we even have a single entry point when with builds that bundle into a single file? I think we ran into this during the docs-PR as well so at some point we recommended importing what you can from |
but for this, eslint will likely force you to have a direct dependency on |
I ran into the same error
To fix that I wrapped all components that imported from '@tanstack/react-query' in components that "use client" and imported all functions used in server components from '@tanstack/query-core'
|
@barbarah Have you already solved that problem? I'm facing the same issue. I cannot prefetch data on server using |
Sorry, no. I've tried the different options mentioned above. But I did not get my sandbox working. I did update the sandbox link because apparently, the link was not working: https://codesandbox.io/p/sandbox/next13-react-query-h4qh77 |
I got it working by doing these step:
@barbarah Here is the working sandbox with the changes I just mentioned. |
Good job! |
@mk965 Just updated the sandbox, you just have to disable revalidateOnMount for the hydrated useQuery hook. |
I finally did some digging and thinking on this today and thought I'd document my findings:
I think we should:
|
Actually, what we could do now as a temporary fix is add |
I got nerdsniped and built a Rollup plugin to preserve directives: https://github.com/Ephem/rollup-plugin-preserve-directives I'll do some more testing, but with this I think we should be able to make it all work as per the docs. |
please try it with: |
I did every thing including Provider file that has 'use client' directive and everything i found, Does this occurs because of next 13.3.0? (provided examples in this thread are using version 13.1.x) |
Hello Everyone! Need a feedback or suggestion if any |
try to import dehydrate from '@tanstack/query-core' instead '@tanstack/react-query' |
I have also been able to get it to work with next version >=13.3.0 and @tanstack/* version 4.29.12 |
I just found the fix, In my case I was using one Rule is if you're using any client side library then make sure that you're not using it's client apis/functions of library directly or indirectly on server routes or server actions. |
This worked, and this is an outline of what I am using
|
Describe the bug
when adding react-query to next 13 i get following error when running
code
Your minimal, reproducible example
https://github.com/JonasWijne/next-test-react-query
Steps to reproduce
Expected behavior
as a user i expect it to compile/dev serve
How often does this bug happen?
Every time
Screenshots or Videos
Platform
TanStack Query version
4.24.4
TypeScript version
4.9.5
Additional context
No response
The text was updated successfully, but these errors were encountered: