swr: Can not mutate data from SWRInfinite with `revalidateFirstPage: false` when key is not mounted

Bug report

I can not manually refresh data using mutate when using SWRInfinite and revalidateFirstPage: false and key of that mutate is not bound to current page.

Description / Observed Behavior

I have a list of items, which I fetch using useSWRInfinite. Since I do not want to fetch the first page everytime user fetches next page, I use it with revalidateFirstPage: false option, and that works great. So, imagine I have a list of items: A, B, C, D, E. Each item have also its own details page. I can change item A to Aa and use mutate when I am on list page to refresh cache without calling request again, and that also works. The problem is when I go to page A and change that item’s name to Aa - even though I call exactly the same methods, when I go back to list page, the item is still A, not Aa. I tested it a lot of times, and that scenario works when I remove revalidateFirstPage: false from useSWRInfinite. But without it I have to load first page every time user scrolls down, which slows down loading new data…

Expected Behavior

Cache is always updated when using mutate, but first page is not fetched everytime when I want to fetch n+1 page

Additional Context

SWR version 1.2.0

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 21

Most upvoted comments

We don’t really understand why the revalidateFirstPage option is not set to false by default ? In which cases we need to revalidate the first page in each size changes ? I don’t understand this feature…

I have the same issue, if we put revalidateFirstPage: false we can’t mutate the keys cached, this has to be a bug, because why i can’t mutate all the pages from swrInfinite when that option is in false but i can o true