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

Revalidate stale data when mutate occurs and useSwr is not mounted #2264

Closed
bordeo opened this issue Dec 6, 2022 · 2 comments
Closed

Revalidate stale data when mutate occurs and useSwr is not mounted #2264

bordeo opened this issue Dec 6, 2022 · 2 comments

Comments

@bordeo
Copy link

bordeo commented Dec 6, 2022

Bug report

Description / Observed Behavior

Mutating an unmounted useSwr key previously validated will not trigger revalidation when revalidateIfStale is false.

Expected Behavior

After a mutation mutate('key') all useSwr() will be revalidate, if not mounted it will revalidate on mount even if revalidateIfStale is false

Repro Steps / Code Example

StackBlitz
StackBlitz steps

  1. Navigate here
  2. Click the link 'mutation page'
  3. Click the button 'Add entry' one or more time
  4. Click the link 'list page'
  5. data is old and it will not revalidate
  6. Click the button "Trigger mutate('/api/list')" to revalidate and the see the updated results

Generic steps

  1. Navigate to a page with a list of items fetched by useSwr
  2. Navigato to another page that trigger mutate of previous key
  3. Navigate to the first page with useSwr

Additional Context

version 1.3.0
config

{
  revalidateIfStale: false,
  revalidateOnFocus: false,
  revalidateOnReconnect: false,
}

similar issue #751
pull request that resolved issue #1498

@bordeo
Copy link
Author

bordeo commented Mar 21, 2023

Still present in 2.1.0 version

Repro Steps / Code Example

StackBlitz

@promer94
Copy link
Collaborator

mutate('/api/list', fetch('/api/add').then((res) => res.json()), {
  revalidate: true,
  populateCache: true
})

This will prevent mutate to update the cache using the result of fetch('/api/add').then((res) => res.json()

and setting

{
        revalidateIfStale: false,
        revalidateOnFocus: false,
        revalidateOnReconnect: false
}

is same as https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations

So this behavior is expected.

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

No branches or pull requests

2 participants