Skip to content

Releases: vercel/swr

1.2.0-beta.1

12 Jan 17:12
d45b05d
Compare
Choose a tag to compare
1.2.0-beta.1 Pre-release
Pre-release

What's Changed

New Contributors

Full Changelog: 1.1.2...1.2.0-beta.1

1.2.0-beta.0

28 Dec 22:52
d1a76c9
Compare
Choose a tag to compare
1.2.0-beta.0 Pre-release
Pre-release

Highlights of This Release

Dedicated API for Optimistic Updates with Auto Rollback on Error

There are now some new options in mutate:

mutate(patchUser(user), {
  optimisticData: user,
  populateCache: true,
  rollbackOnError: true,
  revalidate: true,
})

Here the cache will be immediately updated to user, the โ€œoptimistic valueโ€. And then a request (remote mutation) is started via patchUser(user) and the response will be written to the cache. If that request fails, the original result will be rolled back safely so the optimistic value will be gone. And after all those finish, a revalidation will start to fetch the latest value.

This is extremely helpful for building the optimistic UI pattern.

You can do the same for the global mutate, just remember to pass the key. Also, the current mutate APIs stay unchanged so mutate(data, false) works the same.

Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps.

What's Changed

Full Changelog: 1.1.2...1.2.0-beta.0

1.1.2

26 Dec 20:32
49ee4e9
Compare
Choose a tag to compare

Highlights of This Release

Use the Latest Fetcher Function

SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.

Avoid Unnecessary Auto Revalidations

When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.

New Types for useSWRInfinite

Two types for useSWRInfinite are added: SWRInfinteHook and SWRInfinteKeyLoader. You can use them to type the hook and the getKey function.

New populateCache option for mutate

A new option to control if the mutation data should be written to the cache. You can find the details in #1729.

What's Changed

  • Make polyfill for requestAnimationFrame more robust by @thomaspaulmann in #1707
  • type(infinite): export SWRInfinteHook and SWRInfiniteKeyLoader from infinite, rename InfiniteFetcher to SWRInfiniteFetcher by @houkanshan in #1714
  • feat: Ensure auto revalidations are executed after state updates by @shuding in #1720
  • Add moduleNameMapper to jest by @shuding in #1724
  • Improve test by @promer94 in #1725
  • feat: Use the latest reference of fetcher by @shuding in #1727
  • fix: Re-export InfiniteFetcher by @shuding in #1728
  • feat: Add populateCache option to mutate by @shuding in #1729
  • Fix local state sharing example deps by @huozhi in #1737
  • Merge states for concurrent requests by @shuding in #1741
  • Skip error retrying when document is not active and improve tests by @shuding in #1742

New Contributors

Full Changelog: 1.1.1...1.1.2

1.1.2-beta.1

23 Dec 19:33
68dfcc1
Compare
Choose a tag to compare
1.1.2-beta.1 Pre-release
Pre-release

Highlights of This Release

1. More Tests and Better Code Coverage

We now have 23 test suits of 202 total test cases, with a 98.06% test coverage. The core files and main functionalities are now 100% covered. Kudos to @promer94 for improving it!

2. Use the Latest Fetcher Function

SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.

3. Avoid Unnecessary Auto Revalidations

When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.

4. New Types for useSWRInfinite

Two types for useSWRInfinite are added: SWRInfinteHook and SWRInfinteKeyLoader. You can use them to type the hook and the getKey function.

What's Changed

New Contributors

Full Changelog: 1.1.2-beta.0...1.1.2-beta.1

1.1.2-beta.0

15 Dec 15:44
fd3a649
Compare
Choose a tag to compare
1.1.2-beta.0 Pre-release
Pre-release

What's Changed

New Contributors

Full Changelog: 1.1.1...1.1.2-beta.0

1.1.1

10 Dec 16:06
b78937f
Compare
Choose a tag to compare

Highlights of This Release

Dynamic refreshInterval

You can now pass a function as refreshInterval, to dynamically return the interval (in millisecond) til the next request, based on the current data:

useSWR('key', fetcher, {
  refreshInterval: function (data: Data | undefined) {
    if (!data) return 3000 // Initial request 
    return data.next_update
  }
})

If return 0, polling will be stopped.

What's Changed

New Contributors

Full Changelog: 1.1.0...1.1.1

1.1.0

30 Nov 16:05
16778a7
Compare
Choose a tag to compare

Highlights for This Release

1. Built-in & stable serialization for SWR keys

useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ variables, query: graphql`...` }, fetcher)
// ^all recognized as the same resource

For array keys too, it's safe to do the following:

useSWR([ `...`, { variables } ], fetcher)

2. revalidateFirstPage for useSWRInfinite

This is a new added option for useSWRInfinite (defaults to true), you can use it to control if the first page should be revalidated when changing the size or doing a mutation.

3. Better TypeScript support

  • Key / arguments
  • Conditional / dependent
  • Constant keys
  • Returned data

image

What's Changed

New Contributors

Full Changelog: 1.0.1...1.1.0

1.1.0-beta.12

26 Nov 15:14
b3e6e20
Compare
Choose a tag to compare
1.1.0-beta.12 Pre-release
Pre-release

Patches

  • Chore: rename major branch to main: #1664
  • Fix keyloader index and previousPageData type: #1669
  • Fix: Add defaults for SWRResponse: #1609

Credits

Huge thanks to @huozhi, @promer94, and @TakahiroHimi for helping!

1.1.0-beta.11

24 Nov 15:11
72a5480
Compare
Choose a tag to compare
1.1.0-beta.11 Pre-release
Pre-release

Patches

  • Fix: supports ssr in ie11(#1657): #1659
  • Type: disbale inference when data generic is provided: #1658

Credits

Huge thanks to @Sh031224 and @promer94 for helping!

1.1.0-beta.10

23 Nov 15:12
bb0bd86
Compare
Choose a tag to compare
1.1.0-beta.10 Pre-release
Pre-release

Minor Changes

  • Build: output without minification: #1650
  • Tweak types: #1640

Patches

Credits

Huge thanks to @promer94, @huozhi, and @nguyenyou for helping!