Keep running useMutations while tab is not visible
I have a use case of uploading multiple files to my backend, we have one graphql mutation per upload. And we can support upload 300 files at a time.
They get uploaded synchronously by using a mutation scope.
Every single useMutation is in a separate component... and we have the desire to have the mutations run even when the tab is not visible
(picture attached to help visualize)
The only way I'm seeing to achieve this is with this code:
Is there anything wrong with this approach?
I added the cleanup just in case...

4 Replies
fair-rose•10mo ago
are you saying the mutations aren't starting when the tab is in the background ?
because I think they should
fair-roseOP•10mo ago
i'm not seeing them start in the background.
let me double check
fair-rose•10mo ago
Only retries are paused
fair-roseOP•10mo ago
https://codesandbox.io/p/sandbox/busy-flower-fkvpmj
idk why but it removed my tanstack dep
hmmm this is also not really working when I do that setFocused 😦
i'm seeing when the tab is not visible.. so it's still open in my browser but not visible anymore (i'm focused on another)
idk i the scope has anything to do with it, i'm supposed to process these synchronously
this is the fix
just not sure about cleanup so that once this page is gone it's not overriding my focus stuff
I think I landed on adding eventListener to "visibilitychange" and always setting focused to true