swr
2.5.1 · 12 Aug 2026MIT28.9M / weekRepositoryHomepagenpmAtom feed
1.3.0 is the newest release of 1.x.
In short
1 new2 fixed18 internal
Release note
Highlights of This Release
Optimistic Updates with Auto Error Rollback
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: codesandbox.io/s/swr-basic-forked-k5hps.
user-images.githubusercontent.com/3676859/15138…
.mjs Support
SWR now has .mjs exported for bundlers that prefer this format.
This doesn’t break environments that don’t support .mjs. An alternative .esm.js and CJS bundle are also published.
You can read more about ES modules here.
What's Changed
Optimistic mutation with error rollback
Required return type when mutating
Use the latest reference of fetcher with suspense mode
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.