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 mutate #1075

Merged
merged 1 commit into from
Mar 28, 2021
Merged

Fix mutate #1075

merged 1 commit into from
Mar 28, 2021

Conversation

promer94
Copy link
Collaborator

@promer94 promer94 commented Mar 27, 2021

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 27, 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 536e25e:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration
swr mutate bug PR
swr mutate bug2 PR
useSWR async mutate bug PR
useSWR async mutate bug Issue #1070
swr mutate bug Issue #1074

src/use-swr.ts Show resolved Hide resolved
@jameslouiz
Copy link

For "cache cant update", this works: https://codesandbox.io/s/swr-mutate-bug-forked-95od2?file=/src/index.tsx. Simply conditionally return a fetcher.

@promer94
Copy link
Collaborator Author

For "cache cant update", this works: https://codesandbox.io/s/swr-mutate-bug-forked-95od2?file=/src/index.tsx. Simply conditionally return a fetcher.

if you check the console.log, you will find fetcher never called.
SWR actually never updates the fetcher if the key stay same. In this example, fetcher in SWR is always null

@shuding shuding merged commit 40650e8 into vercel:master Mar 28, 2021
@shuding
Copy link
Member

shuding commented Mar 28, 2021

Thank you!

@promer94 promer94 deleted the fix-mutate branch March 28, 2021 13:13
@jameslouiz
Copy link

For "cache cant update", this works: https://codesandbox.io/s/swr-mutate-bug-forked-95od2?file=/src/index.tsx. Simply conditionally return a fetcher.

if you check the console.log, you will find fetcher never called.
SWR actually never updates the fetcher if the key stay same. In this example, fetcher in SWR is always null

Ah, yes. You're totally right.

This fix would help with a similar issue I have

@jameslouiz
Copy link

I managed to get it working by using isPaused: https://codesandbox.io/s/swr-mutate-bug-forked-95od2?file=/src/index.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants