Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency swr to v1.3.0 #331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Nov 13, 2024

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
swr (source) 1.1.2 -> 1.3.0 age adoption passing confidence

Release Notes

vercel/swr (swr)

v1.3.0

Compare Source

What's Changed

Full Changelog: vercel/swr@1.2.2...1.3.0

v1.2.2

Compare Source

Highlights of This Release

populateCache Option Now Supports Function

We added better Optimistic UI support in v1.2.0. However, what if your API is only returning a subset of the data (such as the mutated part), that can be populated into the cache? Usually, an extra revalidation after that mutation is needed. But now you can also use a function as populateCache to transform the mutate result into the full data:

await mutate(addTodo(newTodo), {
  optimisticData: [...data, newTodo],
  rollbackOnError: true,
  populateCache: (addedTodo, currentData) => {
    // `addedTodo` is what the API returns. It's not
    // returning a list of all current todos but only
    // the new added one.
    // In this case, we can transform the mutate result
    // together with current data, into the new data
    // that can be updated.
    return [...currentData, addedTodo];
  },
  // Since the API already gives us the updated information,
  // we don't need to revalidate here.
  revalidate: false,
});

The new definition:

populateCache?: boolean | ((mutationResult: any, currentData: Data) => Data)

Here is a demo for it: https://codesandbox.io/s/swr-basic-forked-hi9svh

Bug Fixes

What's Changed

Full Changelog: vercel/swr@1.2.1...1.2.2

v1.2.1

Compare Source

Highlights of This Release

shouldRetryOnError accepts a function

Previously shouldRetryOnError is either true or false. Now it accepts a function that conditionally determines if SWR should retry. Here's a simple example:

const fetcher = url => fetch(url).then(res => {
  // Fetcher throws if the response code is not 2xx.
  if (!res.ok) throw res
  return res.json()
})

useSWR(key, fetcher, {
  shouldRetryOnError: (error) => {
    // We skip retrying if the API is returning 404:
    if (error.status === 404) return false
    return true
  }
})

Thanks to @​sairajchouhan for contributing!

What's Changed

New Contributors

Full Changelog: vercel/swr@1.2.0...1.2.1

v1.2.0

Compare Source

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: https://codesandbox.io/s/swr-basic-forked-k5hps.

CleanShot.2022-01-27.at.15.39.58.mp4
.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

New Contributors

Full Changelog: vercel/swr@1.1.2...1.2.0


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
arbitrum-one-launcher ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 4:23am
arbitrum-rinkeby-launcher ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 4:23am
polygon-mainnet-launcher ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 4:23am
polygon-mumbai-launcher ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 4:23am
root-launcher ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 4:23am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants