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

Infinite does not revalidate all pages when the zeroth one changes #2969

Open
alvvaro opened this issue May 18, 2024 · 2 comments
Open

Infinite does not revalidate all pages when the zeroth one changes #2969

alvvaro opened this issue May 18, 2024 · 2 comments

Comments

@alvvaro
Copy link

alvvaro commented May 18, 2024

Bug report

Description / Observed Behavior

As I've come to understand, SWR Infinite by default always fetches the zeroth page alongside the current one. The data is then compared to the cache, so that if anything on it has changed, it fetches again all pages at once. #1401 (comment)

I cannot seem to trigger this behavior. When the zeroth page changes, all middle pages remain the same, which produces skips and duplicate keys in the list.

Expected Behavior

With the default configuration, SWR should revalidate all pages if the zeroth page does not correspond to its cache.

Repro Steps / Code Example

I've modified the SWR Infinite example of the docs to add a +1 button that appends a new item to the beginning of the list. Click +1 any number of times and then click load more and see how it starts to become more and more inconsistent. The data in the codesandbox is purely local, but I'm able to trigger this with a live API.
https://codesandbox.io/p/sandbox/swr-infinite-forked-qltkgj

ScreenRecording2024-05-18at12 45 48-ezgif com-video-to-gif-converter

Additional Context

The codesandbox I linked uses v2, but I noticed this on my app which has v2.2.5.

@alvvaro alvvaro changed the title Infinite does not revalidate all pages when the first one changes Infinite does not revalidate all pages when the zeroth one changes May 18, 2024
@koba04
Copy link
Collaborator

koba04 commented May 25, 2024

I cannot seem to trigger this behavior. When the zeroth page changes, all middle pages remain the same, which produces skips and duplicate keys in the list.

I think this behavior is for cursor-based API, but your example is a page-based API.

@alvvaro
Copy link
Author

alvvaro commented Jun 4, 2024

You're right, I misread the comment from shuding. He was explicitly talking about cursor-based APIs.

However I'm now more confused, since a cursor sidesteps the content shift problem entirely. The revalidation waterfall he talks about is not necessary in that case? Can this waterfall even happen, like is it a feature that exists in code?

Sorry, I'll be happy to close this issue and open a discussion about this, because I was clearly mistaken.

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