question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mutate() and the deduping interval

See original GitHub issue

Bug report

Description / Observed Behavior

I prefetch and mutate some data when the user hovers a link using mutate(key, data, false) When the user clicks the link, the page is loaded and useSWR revalidates the data.

However, the hover and the click where made within deduping interval.

Expected Behavior

Do not revalidate if mutate(key, data, false) has been called within the deduping interval

Repro Steps / Code Example

export async function prefetch(){
  mutate("/api/data", () => fetcher("/api/data"), false)
}

export function DataPage(){
  const res = useSWR("/api/data", fetcher) // will revalidate even though mutate has been called withing the deduping interval

  return <>
    ...
  </>
}

Additional Context

swr@1.0.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hazae41commented, Aug 24, 2022

For those who don’t want to scratch their heads anymore, wondering why the fuck swr does this, I made my own library.

https://github.com/hazae41/xswr

It uses composition-based hooks and has a very easy learning curve, and 0% weird behaviour.

1reaction
hazae41commented, Aug 31, 2021

I tried and it doesn’t revalidate, but I want it to revalidate if the stale data is older than the deduping interval

Read more comments on GitHub >

github_iconTop Results From Across the Web

API
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >
swr/README.md
97, const { data, error, isValidating, mutate } = useSWR(key, fetcher, options) ... 125, - `dedupingInterval = 2000`: dedupe requests with the same...
Read more >
Can I fetch data only once when using swr?
If you need more time just increase the deduping interval. const { data, error } = useSWR('/api/get.json', fetcher, { dedupingInterval: ...
Read more >
Sswr NPM | npm.io
:+1: Optimistic UI / Manual mutation of the data by using mutate() . ... dedupingInterval: number = 2000 : Determines the deduping interval....
Read more >
Intelligent fetching and caching with SWR - Bekk Christmas
✨ Getting the data · ...where is the cache and the strategy? · ☢️ Mutation · ⛔️ Deduplication · ♻️ Automatic retries ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found