Announcing SWR 2.0
We are excited to announce the release of SWR 2.0! The new version comes with a lot of improvements:
- New useSWRMutation hook
- Enhanced mutation and optimistic UI capabilities
- SWR DevTools
- Preload resource
- Improved React 18 support
And more!
Read our blog post and migration guide: https://swr.vercel.app/blog/swr-v2
What's Changed
- bugfix: make suspense and revalidateIfStale work together by @simowe in #1851
- feat: support functional optimisticData by @huozhi in #1861
- test: fix an act warning by @koba04 in #1888
- breaking: Change the fetcher argument to be consistent with the passed key by @shuding in #1864
- Keep all fields with one single key by @shuding in #1863
- fix: wrong spell by @baojie223 in #1902
- Update React 18 dependencies by @shuding in #1824
- build(deps): bump minimist from 1.2.5 to 1.2.6 by @dependabot in #1903
- type: make type inference simpler by @promer94 in #1908
- type: fix type error on SWRConfig by @Himself65 in #1913
- feat: Hook for remote mutations by @shuding in #1450
- Add isFallback state by @shuding in #1925
- build: output mutation cjs bundle with named exports by @huozhi in #1926
- Add
isLoading
state and refactor the core by @shuding in #1928 - Add
keepPreviousData
option by @shuding in #1929 - types: drop legacy types by @huozhi in #1930
- breaking: Throw error when using suspense on the server side without fallback in React 18 by @shuding in #1931
- type: extends useConfig cache interface by @promer94 in #1938
- remove mount check for react18 by @promer94 in #1927
- lint: dont check unused vars with underscore prefix by @huozhi in #1939
- test: upgrade to jest 28 by @huozhi in #1942
- Fix cache types by @chibicode in #1961
- Improved React 18 support by @promer94 in #1962
- types: fix type regressions by @promer94 in #1966
- fix: mutate args for useSWRInfinite hook by @sanjeev29 in #1947
- build: import with-selector with extension from useESE by @huozhi in #1967
- Bug fixes by @shuding in #1968
- chore: Faster type checking by @shuding in #1969
- fix: try fix codesanbox ci import error by @promer94 in #1971
- Fix race conditions related to optimistic UI by @shuding in #1970
- chore: Add test cases for mutate by @shuding in #1976
- fix: Should always reset to the original data after mutating with optimistic data by @shuding in #1982
- refactor: remove useless ref copy by @promer94 in #1981
- chore: switch to pnpm and turborepo by @promer94 in #1983
- fix: should only update cache when actually start new request by @promer94 in #1986
- chore: save some bytes by @promer94 in #1991
- fix: useSWRMutation - clear error after successful trigger (#1973) by @anirudh1713 in #1995
- Fix typo: getSWRCacahe -> getSWRCache by @sdornan in #2000
- build: do not abort on watch mode when ts erroring by @huozhi in #1992
- chore: add engine field to limit pnpm version by @huozhi in #1990
- test: add test case for #1974 by @promer94 in #2005
- fix: Adding debounce for autocomplete-suggestions example by @Walkeryr in #2017
- BREAKING: rename SWRConfig.default to SWRConfig.defaultValue by @huozhi in #2023
- feat: support functional swr context config by @huozhi in #2024
- test: fix all act warnings by @koba04 in #2031
- feat: add preload function by @koba04 in #2026
- fix: Avoid preloading the resource multiple times by @shuding in #2036
- fix: isLoading and isValidating should always respect cache value by @promer94 in #2048
- Fix ts type generation by @huozhi in #2038
- feat: mutate filter by @huozhi in #1989
- Fix typos by @hiro0218 in #2052
- feat: add DevTools hook by @koba04 in #2016
- Use consistent typing imports by @huozhi in #2061
- Upgrading use-sync-external-store lib by @sanjaiyan-dev in #2063
- Revert swr config generic by @huozhi in #2065
- Fix: raf return type by @huozhi in #2074
- Remove unused info from dummy package.json by @huozhi in #2083
- Use pnpm workspace by @huozhi in #2085
- bump typescript and apply nodenext module resolution by @huozhi in #2084
- Chore: Typos and grammar by @AllanOliveiraM in #2094
- chore: add basic tsdoc by @promer94 in #2089
- types: add generic for SWRInfiniteKeyLoader by @jason89521 in #2104
- fix: add swr/_internal to paths by @jason89521 in #2105
- type: make tsconfig simpler and fix type error by @promer94 in #2115
- chore: exclude .tsbuildinfo from files, reduce install size by @promer94 in #2119
- Reorder exports conditions by @huozhi in #2130
- Upgrade bunchee by @huozhi in #2132
- Bump typescript and assemble pnpm scripts by @huozhi in #2133
- chore: add github actions reporter by @promer94 in #2131
- Dedupe installed swc by @huozhi in #2136
- test: add a test for preload API in effects by @koba04 in #2138
- test: add more isLoading tests for the case a key is null or an error by @koba04 in #2141
- ci: use action/setup-node built-in pnpm cache and bump to node16 by @promer94 in #2142
- test: add tests for dependency collection by @koba04 in #2140
- chore: bump dev deps by @huozhi in #2143
- memoize config values to avoid frequent context propagation by @gnoff in #2149
- Bundle types into one file by @huozhi in #2150
- Revert target option by @huozhi in #2151
- chore: fix missing husky warning by @huozhi in #2160
- Remove downlevelIteration and traverse iterator manually by @huozhi in #2181
- fix: re-render when returned data and fallbackData is the same and keepPreviousData is enabled by @koba04 in #2169
- breaking: Change the error broadcasting behavior in mutations and add
throwOnError
option by @shuding in #2182 - docs: Add JSDoc comments to useSWRMutation by @shuding in #2183
- type: export MutationFetcher by @ssssota in #2184
- Bump bundler by @huozhi in #2187
- resolve swr internal imports as external by @huozhi in #2225
- test: update tests alias to swr subpath exports by @huozhi in #2243
- feat: support functional rollbackOnError by @huozhi in #2242
- Update build target to es2018 by @shuding in #2249
- Fix missing esmodule mark in cjs build by @huozhi in #2251
- fix: pass null fetcher to middleware by @koba04 in #2240
New Contributors
- @simowe made their first contribution in #1851
- @baojie223 made their first contribution in #1902
- @Himself65 made their first contribution in #1913
- @chibicode made their first contribution in #1961
- @sanjeev29 made their first contribution in #1947
- @sdornan made their first contribution in #2000
- @Walkeryr made their first contribution in #2017
- @hiro0218 made their first contribution in #2052
- @sanjaiyan-dev made their first contribution in #2063
- @AllanOliveiraM made their first contribution in #2094
- @jason89521 made their first contribution in #2104
- @gnoff made their first contribution in #2149
- @ssssota made their first contribution in #2184
Full Changelog: 1.2.2...2.0.0