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

useSWRInfinite, first update of key doesn't trigger the proper data fetching #1776

Closed
seedy opened this issue Jan 10, 2022 · 0 comments · Fixed by #1803
Closed

useSWRInfinite, first update of key doesn't trigger the proper data fetching #1776

seedy opened this issue Jan 10, 2022 · 0 comments · Fixed by #1803
Labels
area: pagination Pagination related issues bug Something isn't working

Comments

@seedy
Copy link

seedy commented Jan 10, 2022

Bug report

Description / Observed Behavior

I have a use case of useSWRInfinite where I add filters (as query params) to my paginated request.

I would require each change in filters to trigger a full revalidation of data.

Because my swr key changes when I change my filters, I expected I would require nothing else to implement the use case.

Surprisingly, useSWRInfinite, does not properly refetch data after changing query params in my key.
It seems to happen consistently on the first key update.

Am I missing something here?

Expected Behavior

I expected that any update to the swr key would trigger data fetching.

Repro Steps / Code Example

I updated the demo sandbox (outdated) that you provide in your documentation.

https://codesandbox.io/s/swr-infinite-forked-uibdc?file=/src/App.js:718-729

Here's the surprising behaviour:

When changing a query param impacting useSWRInfinite - getKey, the first occurrence does not consistently trigger an API call

simplescreenrecorder-2022-01-10_15.30.33.mp4

Additional Context

SWR version: 1.1.2

@shuding shuding added area: pagination Pagination related issues bug Something isn't working labels Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: pagination Pagination related issues bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants