🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
focusManager.setEventListener((handleFocus) => {
// Listen to visibilitychange
if (typeof window !== 'undefined' && window.addEventListener) {
window.addEventListener('visibilitychange', () => handleFocus(), false)
^^^^^^^^^^^^^^^^^^^
Create an instance as callback here
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', () => handleFocus())
^^^^^^^^^^^^^^^^^^^
Another function instance here, removeEventListener on
this instance won't remove the eventListener above👆
}
}
})
Describe the bug
Docs on https://tanstack.com/query/v5/docs/framework/react/guides/window-focus-refetching#custom-window-focus-event is a misusage of window.removeEventListener
Your minimal, reproducible example
https://tanstack.com/query/v5/docs/framework/react/guides/window-focus-refetching#custom-window-focus-event
Steps to reproduce
Go to the page below. 👇 https://tanstack.com/query/v5/docs/framework/react/guides/window-focus-refetching#custom-window-focus-event
Expected behavior
We can create a event handler like this 👇
so that we can removeEventListener correctly
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Any browser
Tanstack Query adapter
None
TanStack Query version
5
TypeScript version
No response
Additional context
No response