Skip to content

更新日志

请访问 SWR release page 查看所有的历史版本。

1.2.0-beta.1

发布于 Thu Jan 13 2022.

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.1

1.2.0-beta.0

发布于 Wed Dec 29 2021.

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: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.0

1.1.2

发布于 Mon Dec 27 2021.

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

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2

1.1.2-beta.1

发布于 Fri Dec 24 2021.

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: https://github.com/vercel/swr/compare/1.1.2-beta.0...1.1.2-beta.1

1.1.2-beta.0

发布于 Wed Dec 15 2021.

What's Changed

New Contributors

Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2-beta.0