-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat(plugins): add auto-refetch plugin #97
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for funny-banoffee-0afb46 canceled.
|
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.
Nice! I will come back for tests later
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Thanks for the feedback @posva! Sent some commits to refactor based on your comments. |
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.
There should also be another test that ensures the timer is reset if a new request is fired before the data becomes stale
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Thank you @posva! I've added a new test for this and also accepted & implemented your suggestions. However, two tests are failing:
In both cases, it seems the query was called one less time than expected. I tried to set stale time to 1ms or advancing time by 10000ms but the number of queries remain the same, so I think something in my tests are wrong but I cannot figure out what exactly. Tried using |
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
…rver check to parent scope
All done! The only issue left is the |
Closes #49.
This PR adds a new plugin that enables automatic query refetching when data becomes stale. This provides a simple way to keep data fresh without manual intervention.
Features
Issues and Questions
refresh
hook. I also triedfetch
but the issue wasfetch
is not triggered on initial page load butrefresh
does. So even if the user does nothing regarding the query from initial load, it will be auto-fetched in the background.queryCache.refresh(entry)
. I noticed there are also options likefetch
,invalidate
, andinvalidateQueries
. I usedrefresh
because I understand it has an internal check on the data to see if it is fresh. I did not want to force it withfetch
.I would love your feedback on this. I am happy to work on this further.