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

Fix revalidateIfStale behavior when the key changes #1430

Merged
merged 1 commit into from
Sep 6, 2021
Merged

Conversation

shuding
Copy link
Member

@shuding shuding commented Sep 5, 2021

With the added test, currently 4 requests will be made because a SWR hook will always revalidate when the key changes. However the correct behavior should be treating a key change as a "remount", and using the shouldRevalidateOnMount condition to decide if a revalidation is necessary.

@shuding shuding requested a review from huozhi as a code owner September 5, 2021 22:42
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 5, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dbb0021:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

@shuding
Copy link
Member Author

shuding commented Sep 5, 2021

This bug was originally reported with https://codesandbox.io/embed/happy-nova-kzbzg?file=/src/App.js&codemirror=1.

@huozhi huozhi merged commit e3d4248 into master Sep 6, 2021
@huozhi huozhi deleted the fix/keychange branch September 6, 2021 13:26
@j-xzy
Copy link

j-xzy commented Sep 17, 2021

its breaking change. key has change, never revalidate.

@shuding
Copy link
Member Author

shuding commented Sep 17, 2021

@whj1995 Are you using revalidateIfStale: false? Can you share an example?

@j-xzy
Copy link

j-xzy commented Sep 28, 2021

@whj1995 Are you using revalidateIfStale: false? Can you share an example?

https://codesandbox.io/s/goofy-silence-4nqf7?file=/src/App.js

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

Successfully merging this pull request may close these issues.

3 participants