On the first rendering, `hasNextPage` is `undefined`, but converted to `true` by the default value.
For intersection observer to trigger correctly without clicking more button, `hasNextPage` needs type casting.
incrementing and decrementing transactions need to happen in an atomic operation, no matter what happens in between; if we increment, but never decrement, we will get to a state where transactions can never become zero - we're basically "leaking" an open transaction. This leads to no observers being informed ever again because we think we still have an open transaction
this can be fixed by using try/finally to always decrement the transactions
* examples: react-native
Same example as in the Expo snack but in Typescript
* docs(examples): react-native: add link to the typescript version in the repo
* fix: use proper type for onAppStateChange
not all runs to createResult are saved on `this.currentResult` (optimistically created updates do not - we just create the result again later). With the fix from #3098, we made sure that memoized select does not run again in those cases by storing every run. However, that now means that we cannot rely on `prevResult.data` because it might still contain outdated data.
The solution is to store a pair of previous selectFn + data and return the exact data that was computed from the previous select fn if we get the exact same function passed
we compute the result optimistically, and then one more time when calling setOptions. Both times run the select function because only setOptions will update the previous result and previous options. storing the "previous" selectFn separately on the observer whenever it was invoked (independent of the fact from where it was called) side-steps the issue
* fix(useInfiniteQuery): fix infinite re-renders when select produced a new result
by correctly forwarding notifyOptions
* fix(useInfiniteQuery): fix suspense test
asserting the length of 3 seems wrong here and was likely only necessary because we triggered one too many re-renders before this fix :)
* fix(queriesObserver): fix getOptimisticResult call
Fix queriesObserver to call getOptimisticResult as before.
This was a bug introduced in PR #2866
* fix(queriesObserver): return observers in same order as queries
Sort returned observer entries to match the order of queries.
Previously, with keepPreviousData: true, the repurposed observers
would be returned last, potentially in different order than the queries.
* docs: add React Native code examples for common use cases
- Online status management
- Refetch on App focus
- Refresh on Screen focus
* docs(react-native): use useOnlineManager example
* fix(useQuery): continue retries if observer unmount and remount
if we are waiting for a retry to happen, unsubscribing he last observer will cancel retries and just return the error; however, if a new observer subscribes in the meantime, we should continue with the ongoing retries.
this is especially important with "strict effects" in react18, where effects are run twice and thus observers are always unsubscribed and re-subscribed immediately.
* fix(useQuery): continue retries if observer unmount and remount
add another test to include query cancellation
* fix(useQuery): cleanup queries even if they have been fetching
* fix(useQuery): cleanup queries even if they have been fetching
do not re-schedule garbage collection if a query is fetching and we never had any observers subscribed; this is necessary to make suspense work, because with suspense, we always throw before we subscribe, so the garbage collection would prematurely remove the query, resulting in an infinite loop
* fix(useQuery): cleanup queries even if they have been fetching
only schedule garbage collection when the last observer unsubscribes rather than in the constructor
this works around the suspense issue because we only add observers after we've loaded as we throw before that.
if you useErrorBoundary, you're likely not observing the error, because you're not using the returned error field - the ErrorBoundary handles the error for you. So when the actual error then happens, we don't inform the observer about it, because we're only informing them if a prop has changed that they are interested in, resulting in the error boundary never being shown.
The solution would be to always track the error property if you've set useErrorBoundary
* fix(devtools): improve devtools container a11y
default element changes to aside from footer because aside
represents a portion of a document whose content is only indirectly
related to the document's main content.
aria-label is also added to replace the text "generic" in a11y tree.
* fix(devtools): add aria to devtools toggle button
aria-expanded indicates open/closed of the menu
aria-haspopup indicates this is a menu button
aria-controls to link to the menu, also added aria-label on the menu to
label it.
Read more: https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-links.html
* fix(devtools): menuitem are visible in a11y tree in closed devtools
This is because the element is just hidden visually, but is still inside
the DOM. The added conditional display only affects the inner container,
which means the animation of opening/closing is reserved.