micro-graphql-react
micro-graphql-react copied to clipboard
useSuspenseQuery is not refreshing the data
Hey, I found the issue with useSuspenseQuery, and I can't find a workaround for it yet, can you please help?
When I use useSuspenseQuery, everything works as expected when user navigates from another views, but, if user navigates to the same view with different set of parameters, the useSuspenseQuery actually triggers the query, but do not update the data variable.
navigate from Home to Listing view:
const { data, loading, loaded } = useSuspenseQuery(query, variables);
render | loading | loaded | data
-------------------------------------------
1 | false | true | {data} - expected, very good, even loading=true was skipped
navigate from Listing to Listing with different variables, example page=2 or query="some search"
render | loading | loaded | data
-------------------------------------------
1 | false | true | {data} - the data variable has the old data yet. Despite the query was triggered in networking, and it has a new data arrived.
The data is never refreshed with a new array that came from the server. Is user navigates away from the view and come back, the data refreshes as expected.
PS. I use const navigate = useNavigate(); navigate('new path');
for the navigation
Hey thanks for the issue. I'm using this hook in my own web app, and it should absolutely re-trigger the query, and refresh the results when the query variables change.
If you could put together a repro on StackBlitz (or wherever, but Stack Blitz is probably the best option) I'd be happy to look into it.
https://stackblitz.com/
@Kostanos Looking at the source for useSuspenseQuery ... the best I can think of is that maybe you're setting the active
option?
Hey, no, I'm not using the active variable in this case. And as I mentioned, the query itself was sent to the server (with active=false, the query will not be send), and has a updated result. But the data variable is not updated. I'll try to set up Stack Blitz later. Very tight now with one project.
Ah yeah - you did say that. That's really crazy. Hope you can get a repro - eager to see what this is.