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

useFragment, returns false data. #11688

Closed
panchaldeep009 opened this issue Mar 15, 2024 · 6 comments · Fixed by #11689
Closed

useFragment, returns false data. #11688

panchaldeep009 opened this issue Mar 15, 2024 · 6 comments · Fixed by #11689

Comments

@panchaldeep009
Copy link

Issue Description

There is a re-render instance where the useFragment returns the wrong data for the requested cache id.

Screen.Recording.2024-03-15.at.1.20.37.PM.mov

It is only for 1 or 2 render cycles, eventually, it re-renders and returns correct data. but the expected behavior should never return the wrong data for a cache ID.

Link to Reproduction

https://stackblitz.com/edit/vitejs-vite-po6ehx?file=src%2FApp.tsx

Reproduction Steps

useFragment returns User 1 data for User 2 cache ID therefore based on code setup it will throw an exception that User id does not match Expected: 2, Actual: 1

@apollo/client version

3.9.7

@panchaldeep009 panchaldeep009 changed the title useFragment, returns false data. useFragment, returns false data. Mar 15, 2024
@jerelmiller
Copy link
Member

Hey @panchaldeep009 👋

I have a good idea on what might be happening here. Just to confirm, are you seeing another render after props change with the correct data? My guess is you're seeing this timeline:

render id: 1 -> render User:1
change props to id: 2 -> render User:1
render User:2

When you should be seeing this timeline:

render id: 1 -> render User:1
change props to id: 2 -> render User:2

I think we might have a gap in our tests unfortunately that didn't catch this earlier. Thanks for reporting!

@panchaldeep009
Copy link
Author

Hey @panchaldeep009 👋

I have a good idea on what might be happening here. Just to confirm, are you seeing another render after props change with the correct data? My guess is you're seeing this timeline:

render id: 1 -> render User:1
change props to id: 2 -> render User:1
render User:2

When you should be seeing this timeline:

render id: 1 -> render User:1
change props to id: 2 -> render User:2

I think we might have a gap in our tests unfortunately that didn't catch this earlier. Thanks for reporting!

Yes, I was able to see the correct data on the next render cycle.

@jerelmiller jerelmiller self-assigned this Mar 15, 2024
@jerelmiller
Copy link
Member

Awesome thank you! I'll try and get to this as soon as I can.

@jerelmiller
Copy link
Member

I've got a PR open to fix this: #11689. I would expect this to go out sometime next week. Thanks again for raising the issue!

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants