0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-18 19:33:22 +00:00
Commit graph

5,624 commits

Author SHA1 Message Date
allcontributors[bot]
98fbec5896
docs: add arnaudbzn as a contributor for code, doc (#3157)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2022-01-04 22:25:40 +01:00
Arnaud
d779df14e9
docs(examples): add react native expo snack example (#3156) 2022-01-04 22:15:51 +01:00
Dominik Dorfmeister
d12d0cf5bc
chore: issue template (#3154) 2022-01-02 12:44:19 +01:00
Dmitriy Fishman
f4eb19421c
docs: Fix a typo in tkdodos-blog.md (#3152) 2021-12-31 11:29:15 +01:00
DidrikLind
93824ec731
refactor(examples): use triple equal instead of double equal (#3135) 2021-12-28 22:12:04 +01:00
Dominik Dorfmeister
d7faf86005
fix(queryObserver): memoized select functions should not return outdated values (#3140) v3.34.7
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
2021-12-28 18:34:17 +01:00
Damian Osipiuk
b977cf4ddd
refactor(types): use core types in useMutation instead of redefining them (#3122) 2021-12-23 10:13:10 +01:00
Marco Pasqualetti
ca2a57aa4e
fix(devtools): code color is not inherited from panel color (#3115) v3.34.6 2021-12-23 10:07:53 +01:00
Dominik Dorfmeister
3981f5219a
fix(query): set error to null when going to loading state (#3106) v3.34.5
to be aligned with the types, as `loading` cannot have an `error` set.
2021-12-17 12:54:54 +01:00
Dominik Dorfmeister
2054f5b227
fix(queryObserver): make sure that memoized select function only runs once per input (#3098) v3.34.4
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
2021-12-15 19:52:32 +01:00
François Robichet
f9077bcb2c
docs: Add cacheTime default (#3094) 2021-12-14 20:05:53 +01:00
Dominik Dorfmeister
128e578c08
fix: unsubscribe correctly in onlineManager and focusManager (#3092) v3.34.3 2021-12-14 13:08:19 +01:00
Jbee
078114254d
fix(core): remove enabled condition in queryObserver for suspense (#3093)
* fix(core): remove enabled condition in queryObserver

https://github.com/tannerlinsley/react-query/issues/2434

* chore: add missing test case

* chore: fix format
2021-12-14 13:07:29 +01:00
Clifford Fajardo
988ba10a71
chore: update bug report template (#3089) 2021-12-13 07:16:57 +01:00
Dominik Dorfmeister
ca335dec7b
fix(useInfiniteQuery): fix infinite re-renders when select produced a new result (#3081) v3.34.2
* 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 :)
2021-12-10 13:47:00 +01:00
Hyeonsu Lee
0f00cda954
docs: Make react-native example up-to-date #3057 2021-12-10 13:14:30 +01:00
Clement Bowe
e4da8dd10b
docs: Update does-this-replace-client-state.md (#3070) v3.34.1
changed "any boilerplate code that use"  to boilerplate code that was used" to improve the clarity of the sentence.
2021-12-09 20:37:16 +01:00
allcontributors[bot]
ebf1e68a52
docs: add jvuoti as a contributor for code (#3053)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-12-04 22:57:25 +01:00
Janne Vuoti
2ec1979f9c
fix(queriesObserver): fix getOptimisticResult, order of returned observers (#3052)
* 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.
2021-12-04 22:56:37 +01:00
Arnaud
5fd537e4c2
docs(react-native): add code examples for common use cases (#3042)
* 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
2021-12-03 09:04:11 +01:00
stefanprobst
aec640a595
feat(mutation): add onMutate to MutationCache (#3038) v3.34.0 2021-12-01 06:55:41 +01:00
Dominik Dorfmeister
dc2df1066f
fix(useQuery): continue retries if query unmounts and remounts (#3032) v3.33.7
* 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
2021-11-28 08:17:22 +01:00
Janne Vuoti
c51498a935
fix(useQueries): search for unused observers if keepPreviousData (#2680) (#2866) v3.33.6 2021-11-26 21:06:00 +01:00
Alec Flett
c6906b3c4d
fix(useQueries): add useMemo to useQueries to keep result stable (#2992) v3.33.5 2021-11-24 20:07:44 +01:00
Timo Dörr
f18881d27b
docs: add pitfalls section for window focus refetching (#3018) 2021-11-24 08:48:24 +01:00
Tomer
911477422f
docs(query-keys guide): change "And" to "An" (#3010) 2021-11-23 12:03:21 +01:00
Dominik Dorfmeister
0aafb42fcc
fix(query): make sure prefetched queries can be garbage collected (#3007) v3.33.4 2021-11-22 17:40:11 +01:00
Dominik Dorfmeister
27e72de267
fix(useQuery): cleanup queries even if they have been fetching (#2950) v3.33.3
* 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.
2021-11-22 14:45:21 +01:00
allcontributors[bot]
ebd22b203a
docs: add babycourageous as a contributor for code, doc (#2995)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-11-20 17:42:36 +01:00
Dominik Dorfmeister
58dc1ce626
fix(useQuery): fix tracked queries and error boundaries (#2993) v3.33.2
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
2021-11-20 08:57:36 +01:00
allcontributors[bot]
c2727c118f
docs: add prateek3255 as a contributor for code (#2970)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-11-18 18:08:49 +01:00
allcontributors[bot]
fe1e9050ed
docs: add EddyVinck as a contributor for code (#2967)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-11-17 21:13:39 +01:00
allcontributors[bot]
27143438ce
docs: add KATT as a contributor for code (#2965)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2021-11-17 19:53:18 +01:00
Dominik Dorfmeister
7948e7a291
chore: remove trailing comma in all-contributorsrc 2021-11-17 19:33:16 +01:00
Andrew Nguyen
16131c30f8
fix(devtools): improve devtools a11y (#2947) v3.33.1
* 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.
2021-11-17 18:16:16 +01:00
Daniel Bartsch
52854795b6
feat(useMutation): meta for mutations (#2906) v3.33.0 2021-11-17 12:30:39 +01:00
Nika Sepiskveradze
62e12e563e
docs(reference): fixed right sidebar width issue (#2952) 2021-11-17 12:29:06 +01:00
Arnaud
1dc4186756
docs(cancel): add graphql-request example (#2948) 2021-11-15 14:09:00 +01:00
Tanner Linsley
c1ae82ba18
Update README.md 2021-11-12 14:18:11 -07:00
Dominik Dorfmeister
2c36b6d9e9
fix(useQuery): don't throw error if errorBoundary has just been reset (#2935) v3.32.3
the fix for disabled queries was wrong, because disabled queries still need to throw if they are fetching due to some other means, like `refetch`. However, if a query has just been reset, we want to skip throwing for one render cycle. The useEffect that clears the reset will then make sure that further errors will be thrown
2021-11-12 22:11:12 +01:00
Dominik Dorfmeister
d3d7fc4451
fix(useQuery): make sure that disabled queries in error state don't throw (#2933) v3.32.2 2021-11-12 14:34:08 +01:00
Dominik Dorfmeister
57f47e13e1
docs: improve cancellation docs (#2932) 2021-11-12 13:19:37 +01:00
Bernhard Wittmann
35346218bc
docs(optimistic-updates): ease wording in introduction (#2908) 2021-11-11 08:58:20 +01:00
Emmanouil Zoumpoulakis
8065a7e8ed
docs: Typo fixes in Markdown files (#2910) 2021-11-10 20:43:07 +01:00
Arnaud
c118513e83
test(core): 100% code coverage (#2904)
* refactor(logger): assume that console is always defined

* test(utils): isPlainObject: should return `false` if the object has a modified prototype

* test(utils): scheduleMicrotask should throw an exception if the callback throw an error
2021-11-09 11:12:57 +01:00
Louis Law
c917ff7210
chore: add missing eslint-config-prettier for example, (#2898) 2021-11-08 17:25:01 +01:00
Arnaud
c989bde9e1
test(core): improve code coverage (#2876)
* test(InfiniteQueryObserver): should error if queryFn not defined

* test(InfiniteQueryObserver):  should not refetch the first page if refetch another page

* fix(logger): logger is always defined with the console

* test(InfiniteQueryBehavior): move new tests to InfiniteQueryBehavior

* test(QueryCache): add and remove tests

* test(QueryCache): add find with filters.exact defined

fix test.only on previous commit too.

* test(QueryCache): return all queries when no filters are set

fix: comparison in find(); filters object is always defined but could be empty.

* test(mutationObserver): add onUnsubscribe and notify tests

notify: there is no use case in the lib with listeners set to false.

* test(queriesObserver): should not destroy the observer if there is still a subscription

* test(queriesObserver): onUpdate should not update the result for an unknown observer

No onUpdate use case has been found with a possible unknown observer.

* test(queryObserver): the retrier should not throw an error when reject if the retrier is already resolved

* test(InfiniteQueryBehavior): add signal support

* test(hydration): dehydrateQueries false, mutation state pause, hydratedState empty

* test(focusManager): add full coverage tests

* test(query): should set default options

* test(query): should refetch the observer when online method is called

* test(query: should not add an existing observer

* test(query): should not try to remove an observer that does not exist

* test(query): should not dispatch on invalidate if already invalidated

* test(query): reducer should return the state for an unknown action type

Typescript made this case not possible.

* test(query): fetch should not dispatch fetch if meta has not changed

* test(queryClient): setQueryData should use prev data if isDataEqual fct is true

* test(queryClient): setQueryData should set the new data without comparison if structuralSharing is set to false

move related tests into 'setQueryData' test suite

* test(query): fetch should not set the signal  if AbortController is undefined

* test(query): fetch should throw an error if the queryFn is not defined

* test(query): fetch should dispatch fetch if is fetching and current promise is undefined

* test(query): constructor should call initialDataUpdatedAt if defined as a function

* test(queryObserver): should throw an error if enabled option type is not valid

* test(queryObserver): getCurrentQuery should return the current query

* test(queryObserver): should throw an error if throwOnError option is true

* test(queryObserver): should not refetch in background if refetchIntervalInBackground is false

* test(queryObserver): should not use replaceEqualDeep for select value when structuralSharing option is true

* test(queryObserver): add placeholderdata related tests

* fix(queryObserver): shouldNotifyListeners: remove useless condition

updateResult function already check the result with shallowEqualObjects

* test(queryObserver): updateResult should not notify cache listeners if cache option is false

* test(queryObserver): add stale timeout notify test

* test(mutation): setState should update the mutation state

setState is not used in the lib, need to force the usage in the test

* test(mutation): addObserver should not add an existing observer

No use case found, need to use the private method for the test.

* Revert "test(mutation): addObserver should not add an existing observer"

This reverts commit 3643be9518.

* test(mutation): addObserver should not add an existing observer

* test(mutation): executeMutation should throw an error if no mutationFn found

* test(mutation): cancel mutation should not call mutationFn if the current retrier is undefined

Force retryer to undefined because no use case has been found.

* Revert "fix(logger): logger is always defined with the console"

This reverts commit dd64fda076.

* test(mutation): reducer should return the state for an unknown action type

* test(onlineManager): isOnline: add navigator related tests

* test(onlineManager): setEventListener should use online boolean arg

* test(onlineManager): add setEventListener tests

* test(notifyManager): add notifyFn and batchNotifyFn tests

Add a notifyManagerTest singleton because jest.setup.js override notifyFn value.

* test(queryClient): add focusManager and onlineManager related test

* test(queryClient): cancelQueries should not revert if revert is false

* test(queryClient): refetchQueries should throw if throwOnError is true

* test(queryClient): add cancelMutations test

* test(queryClient): should get defaultOptions

* test(queryClient): should update existing query defaults

* test(queryClient): setMutationDefaults should update existing mutation defaults

* test(utils): parseMutationArgs should return mutation options

* test(utils): matchMutation should return false if mutationKey options is undefined

* test(utils): isPlainObject add tests

* test(core): use @ts-expect-error instead of @ts-ignore when possible

* test(core): export NotifyManager for testing purposes

* test(queryObserver): fix test comment
2021-11-07 13:01:37 +01:00
Arnaud
f03396f217
docs(queryCache): fix subscribe callback arg: event instead of query (#2897) 2021-11-07 12:36:38 +01:00
Martin Brodziansky
9edb305f45
fix(types): Export the Mutation type and change default TVariables from void to unknown (#2892) v3.32.1 2021-11-06 22:43:43 +01:00
New Future
b52b2779b3
feat(persistQueryClient): try to clean the old persistented data when storage full (#2851) v3.32.0 2021-11-06 17:52:40 +01:00