refetchOnWindowFocus not working on in 5.17.15 ?
Hi everyone, I just setup react-query in a new React Vite project, but
refetchOnWindowFocus
doesn't work for some reason.
I tried downgrading to 4.x.x as a sanity check, there it seems to work as expected, is there anything I've missed?
I just checked the v4 and v5 sandboxes, and the same issue seems to be present there:
v4: https://codesandbox.io/p/devbox/tanstack-query-example-react-simple-cn8h2r
v5: https://codesandbox.io/p/devbox/tanstack-query-example-react-simple-lskn7u3 Replies
stormy-goldโข2y ago
have you read the upgrade guide?
rival-blackโข2y ago
The behavior changed from 4 to 5โฆ (in a very positive way)
harsh-harlequinOPโข2y ago
Aha, well that explains it. ๐
I thought I checked the migration guide, but I can see now that I did a page search for "refetchOnWindowFocus" which only yielded one answer.
For anyone else, the change is documented here:
https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#window-focus-refetching-no-longer-listens-to-the-focus-event
And here: https://github.com/TanStack/query/pull/4805
Thank you! ๐
GitHub
fix(focusManager): stop listening for
focus
events by ilyasmez ยท ...Why?
As discussed in #4797, focus event has many caveats, as it's triggered in the following scenarios:
When interacting with an iframe.
When opening/closing a browser dialog (alert, confirm)....
Migrating to TanStack Query v5 | TanStack Query Docs
Breaking Changes
v5 is a major version, so there are some breaking changes to be aware of: