-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Invalidate doesn't work as expected for some of the queries, or components not getting rerendered with new data #3254
Comments
I'll admit, I haven't used the devtools myself in a hot minute, and they may need an overhaul in terms of the data we're sending to it, so I can't reliably interpret this from the screenshot right now. That's totally my fault though, sorry! Basically, first of all, I'm not sure how many queries are active in there and which ones you're expecting to see an update for. But, I'm assuming since you mentioned this that I believe there's two likely candidates of what's causing this, and we can confirm them, but you'd have to post a couple things here for me 🤔 Either:
To validate that it's one of the two, you could validate with the
Afterwards, it's still interesting for us to see whether there's any result, but in all likelihood, you won't see an operation for your query and then we can validate which one of these two issues (if any) it is. To validate the first, we may have to modify the |
@kitten gotcha. Thanks for the quick response.
Yes, it's mounted in 3-4 places, and The idea is mutation As this refresh is not a critical bug for now (as at least it shows Hopefully, it won't fix by itself (I'm in the middle of refactoring) and I'll have data to back bug-fixing efforts :) I just want URQL to work as expected :D I don't want to learn Relay :D (and I hate Apollo) |
Hm, 🤔 So, the query isn't mounted when this issue occurs, but you come back to it? It'd probably be helpful to know whether the bug happens exactly with queries that are unmounted/inactive (i.e. no component that is mounted is using it) when the mutation completes. |
@kitten no, no. The query is ALWAYS mounted. In the nav header, I have a |
Gotcha 👍 then it's more likely that it's a bug in Graphcache |
@kitten Hi, I think I am also experiencing the same issue. I will articulate the case for you. Navbar -I have a dropdown on the NavBar if a user is logged in that dropdown with user name is shown. If the user is not logged then regular buttons are shown. to Login or Register. Navbar is on all pages. I am using NextJs so on a different page, all courses are given. The courses have "Enroll" button option or "Continue Course" option based on if a user is logged in or not. Similar to this there are many pages where the Query that checks if a user is logged in or not is there. So when the user is not logged in I browse the Courses page and it shows Enroll --> Correctly. Then I click the navbar Login button and login with correct credentials. The login works as the Profile changes with the user name on the NavBar. This is happening as I have written and updates after Mutation But now when I access the courses page the page shows enrolled on the same course, where as the user is already enrolled. Once I reload the page it shows me "Continue Course" correctly. Apologies for not sharing a repo with this. But any help in this direction would be helpful. I have tried invalidating the MeQuery - User fetching query but it is not working. Regards The requestPolicy in the above case was set to default "cache-first". Once I change the request policy to "cache-and-network" it works as expected with an additional graphql request. |
@RIP21: Friendly ping here ✌️ I'll close this if this is resolved or there's further inactivity, as I don't really have more indications of this being a bug that's affecting more users, and is more likely to come down to either a specific usage pattern or usage error. If it's a bug, or if we get a reproduction here, I'm happy to come back to it. @nagarajay: What's likely to be happening in your case is that a cache miss occurs here. I'd suggest replacing |
Yeah, it's likely some weird Next bug rather than URQL bug. Also, other issues that I had and we discussed in discussions, about browser freezing etc. It's all was down to Next bugs that happen on redirects and only in production builds. As they were reproducing even when I moved everything back to Apollo. Next just very shitty with Suspense enabled frameworks it seems and it causes some weird incompatibilities on route changes. But only in production. |
This is a minimal reproduction to the issue to run it:
EDIT: stackblitz bugged out often so I changed it to a repo https://github.com/JoviDeCroock/urql-invalidate-repro |
Since we don’t have a full validation here of what happened, do let me know (if you’ve got time of course) if |
I think there might still be an issue with graphcache. Or at least that's what I'm experiencing. I made a simple repro https://github.com/ookil/urql-graphcache. Or maybe it's a totaly different issue with Next app router but invalidated queries are not refetched. You have to reexecute the query to get new data |
I am experiencing the same issue these days with either |
Describe the bug
Basically, I invalidate a bunch of root queries on mutation. It goes through successfully, but then queries that got invalidated are not getting reexeucted from the network. Or it does, and one of the components (freshly rendered) is updated, but the rest of the subscribed to the same query components hold on to old data.
This is how it looks in the dev tools.
Some did refetch as you can see with the green thing, but some are instant weird reexecutions that lead to nothing.
![CleanShot 2023-06-07 at 22 03 59@2x](https://private-user-images.githubusercontent.com/3940079/244184394-7be44be8-a144-4ab6-9ab3-a2617462c230.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4MjI5NDAsIm5iZiI6MTcyMTgyMjY0MCwicGF0aCI6Ii8zOTQwMDc5LzI0NDE4NDM5NC03YmU0NGJlOC1hMTQ0LTRhYjYtOWFiMy1hMjYxNzQ2MmMyMzAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjRUMTIwNDAwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTY5ZDJkMTg5ZDY2YmYxZTcxMzk1ZDgwYmVkNjNjYzRmZjAxMzA1ZjRlZTZlOWJmOTgwODU0ZWEwMjZhNTRmZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.cs93S4knKtaFTlx75d6ckBcrukdGdZ3mkUOGYl5-OQ8)
It looks like a series (15-20 of them) of teardown, execute, update, execute, update, teardown, execute, update.
It's hard to make a reproduction, but this is what my update function looks like.
Maybe I don't understand something?
It's important to note that these two queries are shared extensively in UI through a hook like.
And there are at least 2 consumer components on the page rendered at the point of invalidation.
Since there is no warning against such a thing in docs, it's quite a common pattern in the codebase for very reusable stuff like user info etc. that makes no sense to re-query all the time.
Also, it's important to note that network policy everywhere is the default one, so
cache-first
and notcache-and-network
ornetwork-only
.REPRO ATTACHED HERE IS NOT A REPRO. I don't have time to build a repro, especially since it DOES invalidate others correctly rather 90% of the time so to build one is virtually impossible.
I can hop on a call anytime to show it off to anyone interested if that would be easiest.
Reproduction
https://codesandbox.io/s/urql-issue-template-client-iui0o
Urql version
Validations
The text was updated successfully, but these errors were encountered: