-
Notifications
You must be signed in to change notification settings - Fork 21
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: fetch results cached st not getting latest data #218
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kittybest thanks, just one comment
const approve = useApproveApplication({}); | ||
const approve = useApproveApplication({ | ||
onSuccess: () => { | ||
window.location.reload(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a good practice to reload page on action/success/error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but I don't have better way to call fetch immediately 🤔
How about I made the refetchInterval
to 10 seconds like now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lib has something for immediate refetching values, the docs should have this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I wanna do is to refetch instantly in onSuccess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but make sure you don't call it in a loop, so if there are no new data, just skip refetching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xmad how do you think I changed to something like this now? (but I think the data is not updated right after isSuccess
so should call after something like 3 seconds? the isSuccess
is too fast which is earlier than the transaction succeeded QQ)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xmad how do you think I changed to something like this now?
Can you show what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so now I split some functions out the fetchAttestation.ts
file, and instead of setting cacheInterval
to 0 for uncached fetch, made another file for normal fetch, since the node-fetch-cache
package cannot be imported or called in the browser. Once the application is approved, the useEffect
hook would call normal fetch and merge the results with the original fetch result.
But if it refetch once it's isSuccess
, the attestation is actually not yet updated, so I made it sleep for 5 seconds and refetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good as a temporary solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open an issue for it: #229
45f6618
to
877214a
Compare
877214a
to
8b1c460
Compare
8b1c460
to
1ba8864
Compare
1ba8864
to
d1e12b9
Compare
d1e12b9
to
c777b32
Compare
c777b32
to
7b6c655
Compare
7b6c655
to
ef2f7c5
Compare
Problem or add the approved applications into the list using |
ef2f7c5
to
e84ead8
Compare
e84ead8
to
e1d1cfc
Compare
e1d1cfc
to
53166f4
Compare
53166f4
to
9c4e75e
Compare
9c4e75e
to
f5db990
Compare
f5db990
to
c4f1642
Compare
c4f1642
to
18f8dac
Compare
const timeout = setTimeout(() => { | ||
fetchData(); | ||
clearTimeout(timeout); | ||
}, 5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const timeout = setTimeout(() => { | |
fetchData(); | |
clearTimeout(timeout); | |
}, 5000); | |
const timeout = setTimeout(() => { | |
fetchData(); | |
}, 5000); | |
return () => clearTimeout(timeout); |
18f8dac
to
f6cceb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kittybest thanks!
Description
The attestations are cached for long time, which causes user not getting the latest approved attestations.
Related Issues
close #213