T
TanStack2mo ago
optimistic-gold

refetchOnWindowFocus is not behaving as expected

Hello, everyone in one of my pages i need to use this method I understand that it only works if data is stale so i tried to set staleTime to 0 but after switching tabs data is not refetched, also tried to set refetchOnWindowFocus: 'always' but again not working as expected. Is there a way that i might have dissabled it accidentaly or some other thing i have to consider before using it?
3 Replies
genetic-orange
genetic-orange2mo ago
when switching tabs it should definitely work, however we switched the event from focus to visibilityChange in v5, so if you have multiple windows open and just click between them, it won't trigger.
optimistic-gold
optimistic-goldOP2mo ago
oh yes that was how i tried to test it, in what case would refetch occur then?
fascinating-indigo
fascinating-indigo2mo ago
https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event you can also override this behavior in the focusManager object exported by tanstack query

Did you find this page helpful?