37 Commits

Author SHA1 Message Date
Dominik Dorfmeister
eab6e2c01f chore: adapt release script to new repo name 2022-07-15 20:08:30 +02:00
Dominik Dorfmeister
3ebf0d4d77 docs: make examples point to main instead of master 2022-06-24 15:09:11 +02:00
Dominik Dorfmeister
d12d0cf5bc chore: issue template (#3154) 2022-01-02 12:44:19 +01:00
Clifford Fajardo
988ba10a71 chore: update bug report template (#3089) 2021-12-13 07:16:57 +01:00
Prateek Surana
bfef84c066 chore: Add code coverage report (#2894) 2021-11-06 15:53:11 +01:00
Dominik Dorfmeister
718903debf chore: switch from size-limit to bundlewatch (#2845) 2021-10-27 21:55:12 +02:00
Jan Dh
765830c55a chore: Setup bundle size report (#2837) 2021-10-27 18:05:21 +02:00
Michaël De Boey
e49afc04a7 chore: add tests for Node 16 (#2165) 2021-04-24 09:40:22 +02:00
Tanner Linsley
6182360c81 chore: allow next releases 2021-02-08 13:12:08 -07:00
Tanner Linsley
a11f3359a9 chore: fix publishing 2020-12-16 07:28:49 -07:00
Tanner Linsley
310c222b38 chore: update release config 2020-12-13 23:04:34 -07:00
Tanner Linsley
ac342e237a v3 (#1360)
* feat: initial v3 changes (#1079)

* force website deploy

* docs: v3 updates

* docs: More documentation improvements

* docs: update query filters page

* docs: update query keys

* docs: more updates

* docs: updates

* feat: support multiple subscribers in observers

* docs: useMutation updates

* fix: mutate argument types and state update order

* fix: remove cache argument in cache callback

* fix: move optimistic fetching state into query observer

* fix: make sure default options can be overridden

* fix: type improvements

* feat: memoize select function result

* fix: only suspend when mounting

* docs: refactor to top level pages and multiple api reference pages per export

* test: add remove query test

* feat: add filters client isFetching and useIsFetching hook

* docs: temp move docs back to docs directory

* docs: solve conflicts

* docs: fix queryClient reference

* docs: reorg directory structure

* docs: fix queryClient reference

* docs: fix links

* docs: better phrasing

* docs: force docs build

* docs: update examples

* fix: use updatedAt to check for existing data

* feat: add structural sharing to select result

* refactor: update hashing terminology

* test: add ability to wrap react query updates with React act

* refactor: replace console with logger implementation

* docs: add migration page to navigation

* docs: update installation docs

* refactor: reduce file size

* docs: update examples

* fix: always compare query keys as arrays

* refactor: mark observers as private

* test: update timings in hydration cache time test

* docs: Update queries.md (#1134)

* feat: split mutate into mutate and mutateAsync (#1130)

* feat: split mutate into mutate and mutateAsync

* docs: Update docs/src/pages/guides/mutations.md

Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>

* feat: add bi-directional infinite query support (#1135)

* refactor: reduce file size

* feat: revert to previous state on cancellation

* fix: wait for all queries to cancel

* docs: update cancellation docs

* build: force

* build: add beta build

* build: add beta build

* docs: update comparison

* fix: support infinite cache time when hydrating

* refactor: explicitly mark package side effects

* docs: update comparison

* docs: update comparison

* fix: remove excess exports

* feat: add support for default options when hydrating

* docs: fix links

* feat: add options to setQueryData

* fix: align notify terminology

* feat: Major semver bump

BREAKING CHANGE: Increment Major Version

* fix: always try to fetch if enabled

* feat: bump version

* fix: refetch should create new query when removed

* chore: do not publish beta until we figure this out

* make beta prerelease

* dry run releases

* fix: test dry run semantic release

* release beta releases for realzies

* test: add eslint rule

* docs(useQuery): change manual to enabled (#1167)

* feat: move mutations into the core (#1162)

* feat: tree shake infinite query and support manual updates

* docs: update comparison

* refactor: remove observer factory

* refactor: add subscribable

* refactor: move hasListeners

* refactor: optimize bundle

* fix: add status bools to use mutation result

* feat: api update

* fix: add defaults to UseMutationOptions type

* docs: add pages

* fix: cleanup

* refactor: use queryCache property directly

* docs: Add placeholder data guide

* docs: fix typo

* fix: keep previous query status when fetching

* fix: stop retry when observers unmount

* feat: add additional notify flags

* fix: only keep notify on stale option

* refactor: only batch react callbacks

* test: update timings

* refactor: also batch in suspense

* feat: add hydration support for mutations

* fix: remove query immediately if cacheTime is 0

* fix: prevent infinite fetch loop

* refactor: move refetch logic into observer

* fix: match query key correctly when setting defaults

* test: add query defaults test

* fix: re-add useMutation callback composition

* feat: use set defaults also for observers

* test: add enabled assertion

* feat: add ability to manually control the online and focus state

* docs: update onlineManager documentation

* feat: add discriminated unions for query results (#1247)

* fix: only set state in listeners when provided

* docs: add testing page

* feat: add query function context (#1261)

* feat: add errorUpdatedAt property

* fix: only trigger suspense when loading for the first time

* fix: make sure suspense is always triggered when loading a query

* fix: add ability to type the query key in the query function context

* refactor: make isDataEqual type more specific

* docs: update react native focus code

* fix: make sure to remove the correct query from cache

* test: remove only

* feat: add granular component re-render control

* fix: make sure component re-render when they should

* feat: throw error when QueryClientProvider has not been used to set a query client (#1309)

Also updated docs

* test: add invalidateQueries test

* fix: prevent state update after mutation unmounted

* fix: add defaults to setQueryData

* fix: cancellations for useInfiniteQuery (#1359)

* chore: update TypeScript version (#1314)

* Merge branch 'master' into beta

* fix(hydration): set fetchMeta to null by default to make it serializable (#1371)

* fix(hasPageParam): look for (undefined | null | false) values

* chore: fix linting

* fix: cross-bundle/version query client context

* docs: Update Examples

* docs: update example deps

* docs: keepPreviousData not set in paginated queries docs (#1376)

* docs: typo infinite instead of ininite (#1379)

* feat: devtools are now native to the core repo/npm-package

* feat(persist-localstorage-experimental): temporarily persist cache to disk

* tests: fix linting

* chore: attempt codesandbox import fix

* chore: revert codesandbox fix

* fix(persist-localstorage): add ssr-safety

* docs: fix typos in migration and queries guide (#1387)

Fix typos in guides/migrating-to-react-query-3 and guides/queries.

Fixes #1378

* docs(typos): fix typos in mutations guide (#1392)

* docs: update migration guide

* docs: update comparison

* chore: remove vercel.json

* docs: update comparison

* Update logo.sketch

* feat: reset query utils (#1375)

* feat: reset query utils

* Update queryClient.ts

* Reset query docs and tests (#1393)

* docs: Add resetQueries

* test: Add resetQueries tests

* remove unnecessary queryCache.reset methods

Co-authored-by: Aaron Jensen <aaronjensen@gmail.com>

* types: fix mutation context type

* fix: isFetched and isFetchedAfterMount should include failed fetches

* docs: Persist localstorage plugin

* feat: resetQueries refetches active queries (#1397)

Co-authored-by: Niek Bosch <just.niek@gmail.com>
Co-authored-by: Abhijeet Singh <contact.abhijeetsingh@gmail.com>
Co-authored-by: JP Angelle <jp@angelle.me>
Co-authored-by: Jake Ginnivan <jake@ginnivan.net>
Co-authored-by: Tom Klaver <tomklav@gmail.com>
Co-authored-by: Dmitry Ivanov <liseniss@gmail.com>
Co-authored-by: Corentin Leruth <tinencor@gmail.com>
Co-authored-by: ConneXNL <contact@ivia-solutions.com>
Co-authored-by: Rubén Moya <rmoyarodriguez@gmail.com>
Co-authored-by: Pascal Wegner <p.wegner1992@gmail.com>
Co-authored-by: Amen SOUISSI <48829921+amen-souissi@users.noreply.github.com>
Co-authored-by: Aaron Jensen <aaronjensen@gmail.com>
2020-12-13 19:34:19 -07:00
Tanner Linsley
833f5186b5 build: add beta builds 2020-10-05 14:57:27 -06:00
Niek Bosch
73ccba8612 feat: publish new types (#897) 2020-08-20 10:46:20 -06:00
Rui Saraiva
ee2735d84c chore(actions): revert semantic release action code (#895) 2020-08-20 10:29:17 -06:00
Rui Saraiva
2b26c1ab0d chore(actions): add cache to NPM packages on GitHub actions (#888) 2020-08-19 20:30:27 -06:00
Jonathan Stoye
cbb90f37e2 chore: missing colons in issue template (#800) 2020-07-31 15:05:02 -06:00
Michaël De Boey
10aaac02dc Update test-and-publish.yml (#700) 2020-07-02 19:52:49 -06:00
Tanner Linsley
cee6175ee2 tests: fix suspense test 2020-07-01 08:44:00 -06:00
Michaël De Boey
2032924fbf Update config.yml 2020-06-30 01:55:22 +02:00
Michaël De Boey
4cdcd18fce Update FUNDING.yml (#665) 2020-06-29 17:05:54 -06:00
Tanner Linsley
54d549ec4c Update test-and-publish.yml 2020-06-28 13:46:02 -06:00
Tanner Linsley
ae9c1101ef Update test-and-publish.yml 2020-06-28 10:21:13 -06:00
Tanner Linsley
84d1a19b02 v2
(#585)

- Better query invalidation & refetching, less over-fetching
- Simplified dependent query syntax and new `idle` query state
- Multi-instance polling and interval support
- New query status booleans
- Bidirectional Infinite Queries
- Improved mutation lifecycle
- Better test cleanup utils
- Prep for future SSR enhancements

- The booleans `isSuccess`, `isError` `isLoading` and a new one called `isIdle` have been added to the queryInfo object returned by `useQuery` (and friends) and `useMutation`. These are derived safely from the `queryInfo.status` and are guaranteed to not overlap. In most situations, they are easier to use, less typo-prone than status strings and also more terse for determining what to render based on the status of a query.

  ```js
  const queryInfo = useQuery(queryKey, fn)

  return queryInfo.isLoading ? (
    'Loading...'
  ) : queryInfo.isError ? (
    queryInfo.error.message
  ) : (
    <div>{queryInfo.data}</div>
  )
  ```

- `queryCaches` is now exported, which allows you to clean up all query caches that were created. We do this in our own tests when multiple caches are used for testing and to be thorough.

  ```js
  // test.js
  import { queryCaches } from 'react-query'

  afterEach(() => {
    queryCaches.forEach((queryCache) => queryCache.clear())
  })
  ```

- `fetchMore` now supports an optional `previous` option, which will determine if the data you are fetching is should be prepended instead of appended to your infinite list. eg, `fetchMore(nextPageVars, { previous: true })`

  ```js
  const { fetchMore } = useInfiniteQuery(queryKey, fn)

  return (
    <button
      onClick={() => fetchMore(previousPageVariables, { previous: true })}
    />
  )
  ```

- `refetchInterval` can now be changed on the fly. Check out the auto-refetching example to see it in action!
- `invalidateQueries` (previously `refetchQueries`) now has an option called `refetchActive` that when set to `false` will **not** refetch matching queries that are active on the page.
- `makeQueryCache` now accepts an optional configuration object. The `defaultConfig` object is used to override the default query configuration config to use inside of this cache. The `frozen` option if set to `true` will simulate React Query being run on the server, where no queries are cached for privacy and safety concerns. This is the default when using React Query on the server and is optional. You can also set it to `true` on the server and have it work as it would on the client. More information on this coming soon!

BREAKING CHANGE:

- Do you use falsy query keys for dependent queries?
  - The new way to do dependent queries to instead use the `enabled` config flag. You should move your conditions in your key to the `enabled` option
    - Before
    ```js
    useQuery(ready && queryKey, queryFn)
    ```
    - After
    ```js
    useQuery(queryKey, queryFn, { enabled: ready })
    ```
- Do you use functions as queryKeys for dependent queries?
  - If you use functions as query keys that can potentially throw, you should migrate their logic to the `enabled` config option and use optional chaining to cast them to a boolean
    - Before
    ```js
    useQuery(() => ['user', user.id], queryFn)
    ```
    - After
    ```js
    useQuery(['user', user?.id], queryFn, { enabled: user?.id })
    ```
- Do you expect dependent queries to start in the `success` state?

  - Dependent queries now start in a new `idle` state. You should account for this new state where possible. Most rendering logic should still work if you are checking first for the `loading` and `error` states first, then falling back to the "success" state, but still... it's a good idea to do this

    - Before

    ```js
    const { status, data } = useQuery(key, fn)

    return status === 'loading'
      ? 'Loading...'
      : status === 'error'
      ? error.message
      : data
      ? 'The Data'
      : 'Not Ready'
    ```

    - After

    ```js
    const { status } = useQuery(key, fn

    return status === 'idle' ? 'Not Ready' : status === 'loading'
      ? 'Loading...'
      : status === 'error'
      ? error.message
      : 'The Data'
    ```

- Do you use `queryCache.refetchQueries`?
  - `refetchQueries` has been renamed to `invalidateQueries`. You will need make this rename change for your app to continue working propertly. The name change comes due to some differences in what the function does.
    - Before, any queries that matched the `queryKey` used in `refetchQueries(queryKey)` and were also stale, would be refetched... \*\*even queries that were inactive and not rendered on the screen. This resulted in quite a few queries being refetched regardless of their immediate necessity.
    - Now, with `invalidateQueries`, only queries that are actively rendered will be refetched, while any other matching queries will forcefully be marked as stale.
    - This probably won't affect much performance, but should help reduce overfetching out of the box.
- Did you expect `queryCache.refetchQueries` to only refetch stale queries?
  - The new `invalidateQueries` method will **always refetch matching queries that are active**. All other matched queries that are not active will be immediately marked as stale.
- Do you call `queryCache.refetchQueries` with the `force` option?
  - Before, the `force` option was a way to force queries that were not stale to refetch.
  - Now, he new `invalidateQueries` method will **always refetch matching queries that are active** and all other matched queries that are not active will be immediately marked as stale.
- Do you use a global configuration object to configure React Query?
  - Before, the global configuration object was flat:
    ```js
    const globalConfig = {
      suspense,
      useErrorBoundary,
      throwOnError,
      refetchAllOnWindowFocus,
      queryKeySerializerFn,
      onMutate,
      onSuccess,
      onError,
      onSettled,
      retry,
      retryDelay,
      staleTime,
      cacheTime,
      refetchInterval,
      queryFnParamsFilter,
      refetchOnMount,
      isDataEqual,
    }
    ```
  - Now, the global configuration object has 3 parts. The `shared` section, which is a base set of options that are inherited into the next 2 sections, `queries` and `mutations`, each corresponding to the functionality they are used for in React Query:
    ```js
    const globalConfig = {
      shared: {
        suspense,
        queryKeySerializerFn,
      },
      queries: {
        ...shared,
        enabled,
        retry,
        retryDelay,
        staleTime,
        cacheTime,
        refetchOnWindowFocus,
        refetchInterval,
        queryFnParamsFilter,
        refetchOnMount,
        isDataEqual,
        onError,
        onSuccess,
        onSettled,
        throwOnError,
        useErrorBoundary,
      },
      mutations: {
        ...shared,
        throwOnError,
        onMutate,
        onError,
        onSuccess,
        onSettled,
        useErrorBoundary,
      },
    }
    ```
- Do you use "optional query variables" eg. `useQuery(queryKey, optionalVariables, queryFn)` or `useQuery({ variables })`?
  - Optional variables have been removed. They were not used by many and also were unnecessary seeing how you can inline them into your query function
  - Before
    ```js
    useQuery('todos', [optional, variables], queryFn)
    ```
  - After
    ```js
    useQuery('todos', (key) => queryFn(key, optional, variables))
    ```
- Do you use the `globalConfig.refetchAllOnWindowFocus` config option?
  - `refetchAllOnWindowFocus` has been renamed to `refetchOnWindowFocus` to match the option in the configuration object for `useQuery` and friends.
- Do you use the `refetch` function returned by `useQuery` and friends?
  - Previously this `refetch` function would not trigger an actual refetch if the query is not stale.
  - Now, calling this `refetch` will always trigger a refetch, regardless if the query is stale or not.
- Do you expect `prefetchQuery` to skip the first render of `useQuery` instances that render after it?
  - Previously, the first `useQuery` call after a `prefetchQuery` would be skipped all the time.
  - Now, the `staleTime` of a `prefetchQuery` instance is honored. So, if you call `prefetchQuery(key, fn, { staletime: 5000 })`, and then `useQuery(key, fn)` is rendered within those initial 5000 milliseconds, the query will **not refetch in the background, since it is not stale yet**. Likewise, if the stale time has been reached by the time `useQuery(key, fn)` renders, **it will refetch in the background**, since it is stale when `useQuery` mounts/renders.
- Do you use `prefetchQueries`' `throwOnError` or `force` options?
  - `prefetchQuery`'s `throwOnError` and `force` options are now located in a fourth argument, after the query config.
  - Before
    ```js
    prefetchQuery(key, fn, { ...queryConfig, throwOnError: true, force: true })
    ```
  - After
    ```js
    prefetchQuery(key, fn, queryConfig, { throwOnError: true, force: true })
    ```
- Do you call `mutate()` with additional side-effect callbacks? eg. `mutate(vars, { onError, onSuccess, onSettled })`

  - There are no code changes here, however previously, `mutate()`-level side effects would run _before_ side-effects defined in `useMutation`. That order has been reversed to make more sense.
  - Now, the side-effect callbacks in `useMutation` will be fired before their `mutate`-level counterparts.
  - Before

    ```js
    const mutate = useMutation(fn, {
      onSuccess: () => console.log('I will run second'),
    })

    mutate(vars, { onSuccess: () => console.log('I will run first') })
    ```

  - After

    ```js
    const mutate = useMutation(fn, {
      onSuccess: () => console.log('I will run first'),
    })

    mutate(vars, { onSuccess: () => console.log('I will run second') })
    ```

- Do you use `setQueryData` to update multiple queries with a single query key? eg. `setQueryData('todos', newData)` and expect queryKeys `['todos', 1]` and `['todos', 2]` to both get updated?
  - `setQueryData` no longer allows updating multiple queries at once (via prefix matching). If you need to update multiple queries with the same data, you can use the `queryCache.getQueries()` function to match all of the queries you want, then loop over them and use their `query.setData` function to set all of them to the same value.
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
Co-authored-by: Pepijn Senders <PepijnSenders@users.noreply.github.com>
Co-authored-by: Jack <jack.m.ellis@hotmail.co.uk>
Co-authored-by: Jack Ellis <jack.ellis@godaddy.com>
Co-authored-by: Jake Ginnivan <jake@ginnivan.net>
2020-06-22 15:47:18 -06:00
Tanner Linsley
6b65427794 Update test-and-publish.yml 2020-06-16 20:11:44 -06:00
Jason O'Neill
06feac8a2d chore: upgrade dependencies (#583)
* chore: upgrade dependencies

* add workaround for suspense test

* remove size workflow
2020-06-14 19:15:18 -06:00
Tanner Linsley
e6d70bd85d Update issue templates 2020-06-11 15:14:06 -06:00
Tanner Linsley
a130369c02 Create config.yml 2020-06-11 15:13:06 -06:00
Tanner Linsley
55e4f75954 Delete links-test.yml 2020-06-09 16:19:39 -06:00
Rohit Garg
ff5d6a7518 chore(github action): Detect broken links in documentation (#473)
* chore(github action): Detect broken links in documentation

* docs: update name
2020-05-09 10:21:09 -06:00
Rohit Garg
7e38bd2e7a Semantic release support (#403)
* chore: Using semantic release for publishing and changelog generation

* sync master (#1)

sync master (#1)

* Semantic release support (#2)

chore: Using semantic release for publishing and changelog generation

* chore: Correcting action indentation

* build: test semantic release of react-query

* feat: A new feature

* fix: yarn install (#3)

* feat: renaming module for test

* feat: change pkg name

* chore: adding yarn install

* doc: revert vscode settings

* Update package.json
2020-05-05 11:02:56 -06:00
Tanner Linsley
aea14b4006 v1.0.8 2020-03-02 11:47:34 -07:00
Ben Monro
8c890b7089 chore: add tests.yml build action to run tests on PR / master. (#177)
* Create test.yml

* Update test.yml

* added jest config

* fixed typo

* covg threshold

* consolidating package.json

* frozen lockfile

* rename tests for badge
2020-03-01 13:34:27 -07:00
Tanner Linsley
5f16a500e9 v1 (#150)
* Checkpoint

* Split to separate files

* Less exports

* Update useQuery

* v1.0.0-alpha.0

* Refactor to queryCache, reorg files

* v1.0.0-alpha.1

* Fixes

* Update main.yml

* Update main.yml

* Update main.yml

* Include Helpers

* v1.0.0-alpha.2

* Clean up deps

* v1.0.0-alpha.3

* Query Cache + tons more and docs

* v1.0.0-alpha.4

* [next] add some tests (#143)

* add usePaginatedQuery test

* fix setQueryData test

* Update utils.js

Fix #147

* Update useMutation.js

* Created the queryFnParamsFilter config option for useQuery

* Update README.md

* Update queryCache.js

* Create settings.json

* Fixes

* v1.0.0-alpha.5

* Update Readme and build

* Update README.md

* Update README.md

* Update CHANGELOG.md

* New default for refetchOnMount = true

* Update package.json

* [next] Regression tests (#148)

* add useQuery ssr test

* add useQuery test

* add test for dependent queries

* add default status test

* add status test in manual mode

* add test

* format test files

* expand dependent queries test

* ignore __tests__/shared folder

* match test files by .test.js filename instead of __test__ folder

* do not cache queries with undefined queryHash

Fixes https://github.com/tannerlinsley/react-query/issues/137

* format

* fix typos

* Merge with fixes for regressions

* update size-plugin

* remove size-plugin

Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>

* Remove size plugin

* Update useMutation test to not be so noisy.

Co-authored-by: Andrew Cherniavskii <andrew.cherniavskii@gmail.com>
2020-02-26 11:38:26 -07:00
anotherjsguy
d0c0d28349 set-up size-plugin-bot 🤖 (#56)
* setup size-plugin-bot

* update rollup-plugin-size version

* add build script to travis config
2019-11-29 15:25:00 -07:00
Tanner Linsley
fa9ee84b75 Update FUNDING.yml 2019-11-04 14:39:58 -07:00
Tanner Linsley
ce7e940f3b Create FUNDING.yml 2019-11-04 14:39:48 -07:00