Highlights
Better React 18 Support (#1962)
This is a change of SWR's internal implementation detail. For developers that use SWR, it will just work out of the box without any changes in their apps.
Brought to you by @promer94 and @shuding, this release includes a core refactoring that improves React 18 support by adopting APIs like useSyncExternalStore
and startTransition
internally. Especially when rendering UIs concurrently with React 18, this new SWR version ensures stronger UI consistency.
Worth note that the current stable 1.x version of SWR still works well in React 18.
This core change isn't breaking and does not affect React <=17 apps.
Breakings
Avoid using Suspense on the server-side (#1931)
When using suspense: true
with SWR on the server-side (including pre-rendering in Next.js), it's now required to provide the initial data via fallbackData
or fallback
. This means that you can't use Suspense to fetch data on the server side as of today, but either doing fully client-side data fetching, or fetch the data via the framework (such as getStaticProps
in Next.js).
While Suspense for libraries is still experimental, this behavior might change before the 2.0 stable release. More discussions can be found here: #1906.
What's Changed
- breaking: Throw error when using suspense on the server side without fallback in React 18 by @shuding in #1931
- feat: Improved React 18 support by @promer94 in #1962
- fix: Fix cache types by @chibicode in #1961
- fix: Remove mount check for react18 by @promer94 in #1927
- fix: Mutate args for useSWRInfinite hook by @sanjeev29 in #1947
- fix: Import with-selector with extension from useESE by @huozhi in #1967
- fix: Bug fixes by @shuding in #1968
- fix: Fix race conditions related to optimistic UI by @shuding in #1970
- type: Extends useConfig cache interface by @promer94 in #1938
- type: Fix type regressions by @promer94 in #1966
- chore: Don't check unused vars with underscore prefix by @huozhi in #1939
- chore: Upgrade to jest 28 by @huozhi in #1942
- chore: Faster type checking by @shuding in #1969
- chore: Fix codesanbox ci import error by @promer94 in #1971
New Contributors
- @chibicode made their first contribution in #1961
- @sanjeev29 made their first contribution in #1947
Full Changelog: 2.0.0-beta.1...2.0.0-beta.3