Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Deps: Update dependency swr to v2. #170

Merged
merged 1 commit into from
Aug 6, 2023
Merged

Deps: Update dependency swr to v2. #170

merged 1 commit into from
Aug 6, 2023

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Mar 18, 2023

Mend Renovate

This PR contains the following updates:

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

Release Notes

vercel/swr (swr)

v2.2.0

Compare Source

What's Changed

New Contributors

Full Changelog: vercel/swr@v2.1.5...v2.2.0

v2.1.5

Compare Source

What's Changed

Full Changelog: vercel/swr@v2.1.4...v2.1.5

v2.1.4

Compare Source

What's Changed

New Contributors

Full Changelog: vercel/swr@v2.1.3...v2.1.4

v2.1.3

Compare Source

What's Changed

New Contributors

Full Changelog: vercel/swr@v2.1.2...v2.1.3

v2.1.2

Compare Source

Patches
  • Improved type inferring for swr/subscription
  • Adding SWRSubscriptionOptions type for swr/subscription

Changes

New Contributors

Full Changelog: vercel/swr@v2.1.1...v2.1.2

v2.1.1

Compare Source

Patches

Documentation

New Contributors

Full Changelog: vercel/swr@v2.1.0...v2.1.1

v2.1.0

Compare Source

Feature

Checkout subscription docs and useSWRInfinite parallel fetching docs for more details

Patches

Misc

New Contributors

Full Changelog: vercel/swr@v2.0.4...v2.1.0

v2.0.4

Compare Source

Patches

Misc

New Contributors

Full Changelog: vercel/swr@v2.0.3...v2.0.4

v2.0.3

Compare Source

Patches

Chores

New Contributors

Full Changelog: vercel/swr@v2.0.2...v2.0.3

v2.0.2

Compare Source

Patches

Chores

Full Changelog: vercel/swr@v2.0.1...v2.0.2

v2.0.1

Compare Source

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: vercel/swr@2.0.0...v2.0.1

v2.0.0

Compare Source

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

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

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

v1.1.2

Compare Source

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


Configuration

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

🚦 Automerge: Enabled.

Rebasing: Whenever PR is behind base branch, 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 has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/swr-2.x branch from 78be16b to a9b9aae Compare March 23, 2023 21:19
@renovate renovate bot force-pushed the renovate/swr-2.x branch from a9b9aae to d91b607 Compare April 3, 2023 10:07
@renovate renovate bot force-pushed the renovate/swr-2.x branch from d91b607 to c3b60ec Compare April 17, 2023 11:02
@renovate renovate bot force-pushed the renovate/swr-2.x branch from c3b60ec to 35c0573 Compare May 28, 2023 10:57
@renovate renovate bot force-pushed the renovate/swr-2.x branch from 35c0573 to 1fb7cf2 Compare June 22, 2023 22:44
@renovate renovate bot force-pushed the renovate/swr-2.x branch from 1fb7cf2 to 953da80 Compare August 6, 2023 17:36
@vercel
Copy link

vercel bot commented Aug 6, 2023

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

Name Status Preview Comments Updated (UTC)
telemetry 🛑 Canceled (Inspect) Aug 6, 2023 5:54pm

@renovate renovate bot changed the title fix(deps): update dependency swr to v2 Deps: Update dependency swr to v2. Aug 6, 2023
@renovate renovate bot force-pushed the renovate/swr-2.x branch from 953da80 to bb40481 Compare August 6, 2023 17:45
@renovate renovate bot force-pushed the renovate/swr-2.x branch from bb40481 to b89ac81 Compare August 6, 2023 18:04
@filiphsps filiphsps merged commit 391d7d0 into master Aug 6, 2023
@filiphsps filiphsps deleted the renovate/swr-2.x branch August 6, 2023 18:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant