Skip to content
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

server error with nextjs , and hydration in v5 #8528

Open
artainjast opened this issue Jan 13, 2025 · 1 comment
Open

server error with nextjs , and hydration in v5 #8528

artainjast opened this issue Jan 13, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@artainjast
Copy link

Describe the bug

server error with nextjs , and hydration in v5

Your minimal, reproducible example

https://stackblitz.com/github/tanstack/query/tree/main/examples/react/nextjs-app-prefetching?embed=1&theme=light&preset=node&file=src/index.tsx

Steps to reproduce

  1. it does not need any steps , it occur when you starting the app (event on dev or production mode).

Expected behavior

as a user , i don't except this error happen , and it make some conflicts with building and compiling for production

How often does this bug happen?

Every time

Screenshots or Videos

Image

Platform

  • OS : [MacOS - stackblitz]

Tanstack Query adapter

react-query

TanStack Query version

"^5.64.0" ,

TypeScript version

"5.7.2"

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Jan 14, 2025

Thanks for filing. I’m not 100% sure what’s going on, but I debugged it a bit and the gist is that the initialPromise is passed as undefined to query.fetch here:

const initialPromise = Promise.resolve(promise).then(deserializeData)
// this doesn't actually fetch - it just creates a retryer
// which will re-use the passed `initialPromise`
void query.fetch(undefined, { initialPromise })

That leads to us invoking the queryFn (because we have no promise to re-use), but the queryFn doesn’t exist yet, so it errors:

promiseOrValue = initialPromise ?? config.fn()

When inspecting the promise we get from the server, it’s there, but initialPromise is still undefined:

Image

@juliusmarminge does this have something to do with .then(deserializeData) ? Before that step, the promise seems to still be there. deserializeData is just our default one:

function defaultTransformerFn(data: any): any {
return data
}

@TkDodo TkDodo added the bug Something isn't working label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants