Skip to content
Source
Sign inSign up
TanStack/query

Nextjs 14 - Updating cache makes the data undefined #8144

Send to my agent
ClosedTheMostafaOsamaDev(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

I have a problem when I want to updating the cache in my Nextjs project

  1. First I Prefetch Queryand used the hydration boundary like in the docs/client/app/product/[productId]/page.tsx`

  2. Secondly and where the problem comes when I try to set the cache it makes the cache I want undefined /client/components/SingleProduct.tsx Image

Your minimal, reproducible example

https://codesandbox.io/p/github/TheMostafaOsamaDev/shoop-e-commerce/main?file=%2Fclient%2Fapp%2Fproduct%2F%5BproductId%5D%2Fpage.tsx&import=true

Steps to reproduce

We two directories client and server

  1. Go to each one and install dependencies npm i
  2. Start the NestJS server npm run start:dev
  3. Start the client with npm run dev
  4. In the route page / Go to single product page (Click on the card) and try to add it to wishlist.

Expected behavior

I expect when I update the cache to change the isInWishList to true or false when onMutate

How often does this bug happen?

None

Screenshots or Videos

https://github.com/user-attachments/assets/8ef89b28-28d4-4796-a762-21773f7787e8

Platform

  • Windows 10
  • Chrome
  • When updating the cache

Tanstack Query adapter

None

TanStack Query version

5.56.2

TypeScript version

5

Additional context

Nextjs 14

  1. Start the NestJS server npm run start:dev

    This isn’t a minimal reproduction, this is just your full-blown project. Please trim it down to a minimal reproduction, otherwise, there are too many factors that could be in play here. I will happily re-open and look into the issue once that’s done.

  2. TkDodo closed this

  3. TkDodo added labelsneeds-info

Sign in to join this conversation.