micro-graphql-react icon indicating copy to clipboard operation
micro-graphql-react copied to clipboard

useSuspenseQuery is not refreshing the data

Open Kostanos opened this issue 2 years ago • 4 comments

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

Kostanos avatar Jul 16 '22 10:07 Kostanos

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/

arackaf avatar Jul 18 '22 22:07 arackaf

@Kostanos Looking at the source for useSuspenseQuery ... the best I can think of is that maybe you're setting the active option?

arackaf avatar Jul 18 '22 22:07 arackaf

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.

Kostanos avatar Jul 18 '22 22:07 Kostanos

Ah yeah - you did say that. That's really crazy. Hope you can get a repro - eager to see what this is.

arackaf avatar Jul 19 '22 00:07 arackaf