Skip to content

useSWRInfinite with Next.js router query parameters vs pages #2370

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

Closed
horgen opened this issue Jan 19, 2023 · 2 comments · Fixed by #2386
Closed

useSWRInfinite with Next.js router query parameters vs pages #2370

horgen opened this issue Jan 19, 2023 · 2 comments · Fixed by #2386
Labels
bug Something isn't working

Comments

@horgen
Copy link

horgen commented Jan 19, 2023

Bug report

Description / Observed Behavior

I've noticed that useSWRInfinite is behaving weird in Next.js when using the router query parameters to change the URI key. The issue is only visible after going back or forward in the browser.

Repro Steps / Code Example

I have made a copy of the official infinite example here:

Note: I'm console logging the size to make it easier to see the change in the following cases.

Case 1 (working as expected):

  1. Go to https://swr-infinite-issue.vercel.app
  2. Click the "load more" button two times.
  3. Click the "pages/page.js" link at the top. This will change the URI key by going to a new page (...and remounting all the things).
  4. Go back to the previous page by click the back button in your browser

Result: useSWRInfinite will remember the correct size: 3 of the first page.

Case 2 (not working as expected):

  1. Go to https://swr-infinite-issue.vercel.app
  2. Click the "load more" button two times.
  3. Click the "pages/index.js - 2" link at the top. This will change the URI key by updating a router query parameter.
  4. Go back to the previous page by click the back button in your browser

Result: useSWRInfinite will remember the correct size: 3 of the first page for a second before resetting it to 1.

@viktorrudi
Copy link

+1

@promer94 promer94 added the bug Something isn't working label Jan 26, 2023
promer94 added a commit to promer94/swr that referenced this issue Jan 26, 2023
promer94 added a commit to promer94/swr that referenced this issue Jan 26, 2023
@promer94
Copy link
Collaborator

Thanks for reporting this! The example is really helpful ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants