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

Multiple API requests are fired when increasing the page size of useSWRInfinite #1552

Closed
crushjz opened this issue Oct 13, 2021 · 3 comments
Closed

Comments

@crushjz
Copy link

crushjz commented Oct 13, 2021

Bug report

Description / Observed Behavior

The useSWRInfinite hook fires a double request every time there is a setSize(size + 1) call.

This only happens in SWR version 1.x. Everything works fine with version 0.x.

Expected Behavior

There should only be 1 request per setSize call.

Repro Steps / Code Example

This is the official example found in the pagination documentation. It uses SWR 0.3:

https://codesandbox.io/s/swr-infinite-z6r0r?from-embed=&file=/src/App.js

This is the exact same example, but uses SWR 1.0.1:

https://codesandbox.io/s/swr-infinite-1-0-double-api-call-issue-fbvzs

If you open the network tab, you will see multiple request fired every time you click "load more" .

Additional Context

SWR version: 1.x

@ruijdacd
Copy link

I just encountered this exact issue right now and it seems to happen exclusively on 1.x

@sairajchouhan
Copy link
Contributor

related to #1401

@crushjz
Copy link
Author

crushjz commented Oct 14, 2021

Given #1401, I think this is an expected behavior and the issue can be closed.

As @shuding said there, the solution is:

There is now a revalidateFirstPage option in swr@beta 🎉

@crushjz crushjz closed this as completed Oct 14, 2021
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

3 participants