-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
✅ Deploy Preview for funny-banoffee-0afb46 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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
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
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 |
All done! The only issue left is the |
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>
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>
…rver check to parent scope
8224f86
to
320d9ad
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.
Thanks a ton for the great contribution! It turns out your test was good! Calling the query
mock directly wasn't triggering things, but calling the refetch
method made it work with no code changes!
I also removed the need for a map by storing the timeout in the entry itself, simplifying things and also fixing possible bugs with the serialization of the key (BTW I exposed now a toCacheKey
function that could be used)
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.