-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(focusManager): stop listening for focus
events
#4805
Conversation
The `focus` event had many caveats (as discussed in TanStack#4797), so we now listen only for `visibilitychange` event.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 52f4cda:
|
If you see a refetch that you are not expecting, it is likely because you just focused the window and TanStack Query is doing a [`refetchOnWindowFocus`](../guides/window-focus-refetching). During development, this will probably be triggered more frequently, especially because focusing between the Browser DevTools and your app will also cause a fetch, so be aware of that. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow this is great! I didn't know that it would also fix this issue ❤️
[//]: # 'Example5' | ||
[//]: # 'Example4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should switch to named examples @DamianOsipiuk 😅. I see the vue-query docs only overwrite/use the 'Example'
slot, but this could become tedious with numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you know naming things is hard, so i just went with numbers 🙈
But yeah, probably we should name them properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidentally pressed request changes - i wanted to approve 😅
@TkDodo I believe we should add a note about this to the migration guide. |
aah yes, forgot about that 👍 . |
Hello guys. We have also encountered ux experience issues caused by focus recently and would like to know if this pull request can be merged into version V3. The risk is too high for us to perform a major version upgrade |
it's a breaking change so no. also, it was merged to v5. seems like you haven't upgraded in over a year ... |
Yes. we are keeping using v3. And we fix this by git-patch. Maybe it's time
to upgrade. Thx~
Dominik Dorfmeister ***@***.***> 于2023年7月15日周六 16:19写道:
… if this pull request can be merged into version V3
it's a breaking change so no. also, it was merged to v5. seems like you
haven't upgraded in over a year ...
—
Reply to this email directly, view it on GitHub
<#4805 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACIBOGGUNCILAYE2DVUJ4YDXQJHAPANCNFSM6AAAAAATZUTNZQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@gabrielbrattgard it does whatever the browser visibilitychange does so yes, that's an purpose. You can totally opt back into the |
This is great @ilyasmez! |
@RiccardoRomagnoli, do you really want the page to refetch when the user interacts with it? This might result in content changing under their cursors (e.g. the item they wanted to click is not there anymore, or the position of the item changes). I believe that interacting with the page is already too late. |
This behaviour can be desirable in certain scenarios. E.g. A notification badge counter that can update when a user refocuses on to the browser window. My workaround fix from the comments on this thread plus experimenting with other ways:
If anybody can explain the weird reason why the queries only refetch if manually triggered I'd love to know and improve what I'm doing here. |
Why?
As discussed in #4797,
focus
event has many caveats, as it's triggered in the following scenarios:alert
,confirm
).I think the original idea behind
refetchOnWindowFocus
was to refetch the queries when the user "comes back" to the page, and that's achievable usingvisibilitychange
.Before
You can see that the query is being refetched in many unexpected scenarios, while the user didn't leave the page.
rq-focus-fix-before.1.mp4
After
The query is refetched only when the user stop using the app, and comes back.
rq-focus-fix-after.1.mp4
What does this PR do
focus
event listener infocusManager
.