Skip to content

Releases: vercel/swr

v2.1.0

06 Mar 16:50
Compare
Choose a tag to compare

Feature

Checkout subscription docs and useSWRInfinite parallel fetching docs for more details

Patches

  • fix: use the latest config in useSWRMutation by @koba04 in #2468
  • Fix: type support for suspense and fallbackData(#2396) by @taro-28 in #2452
  • Error should be reset when new data comes by @huozhi in #2472
  • fix: avoid creating new snapshot if cache is not updated at client during streaming by @promer94 in #2475
  • refactor: initialize the cache only on first access by @promer94 in #2479

Misc

New Contributors

Full Changelog: v2.0.4...v2.1.0

v2.0.4

24 Feb 16:28
Compare
Choose a tag to compare

Patches

  • build: fix release job condition by @huozhi in #2392
  • types: fix some mutation type issue by @promer94 in #2421
  • fix: Error retry should be handled by global revalidator instead of local revalidation function by @promer94 in #2415
  • fix: ensure initCache setter function stays within bounds of subscriptions by @lfbergee in #2411

Misc

New Contributors

Full Changelog: v2.0.3...v2.0.4

v2.0.3

28 Jan 12:55
Compare
Choose a tag to compare

Patches

  • fix: parameters passed to subscribe is inconsistent with its declaration by @hong24 in #2353
  • fix: when inifinite key changes, should use cached pagesize instead of initialSize by @promer94 in #2386
  • fix: make compare function only compare data (#2375) by @Retrospection and @promer94 in #2387 #2389
  • fix: initial loading state should be false with revalidation is disabed by @promer94 in #2382
  • fix: Ensure hydration matches the SSR result during streaming by @shuding in #2391

Chores

New Contributors

Full Changelog: v2.0.2...v2.0.3

v2.0.2

26 Jan 13:06
c0090ab
Compare
Choose a tag to compare

Patches

Chores

Full Changelog: v2.0.1...v2.0.2

v2.0.1

18 Jan 17:36
Compare
Choose a tag to compare

In this patch release, we majorly improved typing support and SWR can infer the types based on the configuration.

  • When the suspense option is true, the returned data will exclude undefined and the isLoading will always be false.
  • When the fallbackData option is provided, the returned data will be the same type of fallbackData, and the isLoading will always be false.

Here's a demo for it:

swr-2.0.1.mp4

What's Changed

New Contributors

Full Changelog: 2.0.0...v2.0.1

2.0.0

09 Dec 21:28
14956a8
Compare
Choose a tag to compare

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

New Contributors

Read more

2.0.0-rc.3

28 Nov 15:41
f024b2f
Compare
Choose a tag to compare
2.0.0-rc.3 Pre-release
Pre-release

What's Changed

Full Changelog: 2.0.0-rc.1...2.0.0-rc.3

2.0.0-rc.1

25 Nov 16:30
f5f43b7
Compare
Choose a tag to compare
2.0.0-rc.1 Pre-release
Pre-release

The last RC before SWR 2.0. This release includes several small fixes with one breaking change.

Breaking

In this release, we are dropping IE 11 support, and using ES2018 as the build target. However, when using SWR in a framework or using a bundler (esbuild, Webpack, etc.), you can still target ES5 or using a browserlist configuration to customize this.

The benefit of this change is, we can now use faster native APIs to make SWR more performant, instead of using old alternatives. A benchmark shows a 4.7x speed improvement of the useSWR() function call during SSR, when we change Object.assign({}, a, b) to { ...a, ...b }.

Details can be found in #2249.

What's Changed

New Contributors

Full Changelog: 2.0.0-rc.0...2.0.0-rc.1

2.0.0-rc.0

05 Oct 21:13
c221a28
Compare
Choose a tag to compare
2.0.0-rc.0 Pre-release
Pre-release

The SWR 2.0 release candidate. This RC has one breaking change, a new option for mutation APIs, and some bug fixes & improvements.

Highlights & Breakings

A failed mutation will not cause useSWR's error to be updated:

const { error, mutate } = useSWR('/api/user', getUser)

return <button onClick={async () => {
  try {
    await mutate(updateUser)
  } catch (mutationError) {
    // `mutationError` will not cause `error` to be updated.
  }
}}>Update User</button>

In 2.0, with the example above, error will only be coming from getUser and will be shared across all useSWR('/api/user') hooks. And mutation errors (mutationError) will be coming from mutations like updateUser calls, they will be separated from fetcher errors.

There is also a new option throwOnError for useSWRMutation to disable the default throwing behavior of trigger:

const { trigger } = useSWRMutation('/api/user', updateUser)

try {
  await trigger()
} catch (err) {
  // ... it throws when failed to trigger the mutation so you can
  // easily change the flow here
}
const { trigger, error } = useSWRMutation('/api/user', updateUser, {
  throwOnError: false
})

// You don't need to try-catch here, you can instead handle errors
// on the component level in a declarative way
await trigger()

Read more about this change in #2182.

What's Changed

  • chore: fix missing husky warning by @huozhi in #2160
  • fix: 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

Full Changelog: 2.0.0-beta.7...2.0.0-rc.0

2.0.0-beta.7

12 Sep 17:38
90ad974
Compare
Choose a tag to compare
2.0.0-beta.7 Pre-release
Pre-release

Most changes in this release are maintenance related, as we are finalizing everything for the upcoming 2.0 stable version.

What's Changed

New Contributors

Full Changelog: 2.0.0-beta.6...2.0.0-beta.7