I’m trying to make a React context provider which runs a query, and then allows it’s children to render.
I was thinking it’d be nice to do this with Suspense, because I could have other providers that load essential data for the app, and it would all bubble up to the one boundary and allow me to show a loading spinner for everything without having loader spinners and logic to show the spinners dotted around all over the place.
I’ve made my provider, it fetches the data, and it shows the loading fallback just fine, but it seems like useSuspenseQuery is periodically refetching the data. This is also fine, I actually would prefer to keep that behaviour, the problem I’m having is that it is showing the Suspense fallback (i.e. full-screen loading component…) every time it decides to refetch that data automatically.
All of the guides for suspense I’ve use highlight how you can control this if you’re refetching yourself, but I’m not changing anything here - it’s just doing it on it’s own, so I’m not sure what I can wrap in a transition. There are no variables changing to defer, etc.
I’ve tried to use useDeferredValue on the data returned by the query to pass into the provider, but I think that doesn’t work and wouldn’t make sense because the Suspense boundary is above this component. I’ve also tried using different fetchPolicy and nextFetchPolicy values and have had no luck.
I’m quite new to Suspense in general, so apologies if there’s a really obvious solution to this, I’ve tried to read around the issue, but am just stumped right now. Any help would be much appreciated ![]()