-
Notifications
You must be signed in to change notification settings - Fork 214
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) Disable most automatic revalidations by default #1157
Conversation
Size Change: -84.6 kB (-1.46%) Total Size: 5.72 MB
ℹ️ View Unchanged
|
// only revalidate once every 10 minutes | ||
focusThrottleInterval: 600000, | ||
// disable automatic revalidations by default | ||
revalidateIfStale: false, |
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'm a little more hesitant about turning on revalidateIfStale
. Maybe we leave that out for 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.
I agree. If revalidateIfStale
, revalidateOnFocus
, revalidateOnReconnect
are all set to false, there is no longer a distinction between useSWR
and useSWRInfinite
.
https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations
Side note: Should we have a convention where the SWRConfig values are override-able on a per-app basis? Maybe an edge case, but I'm thinking about multiple clinician using the queues / appointments / ward app and we might want faster re-validate internals.
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.
Yeah, @chibongho. As I mentioned here, SWRConfig
merges the configuration from the parent context. This means that alternative configurations provided further down the line will override the parent values. I've linked to an example video there showing SWRConfig overriding the global configuration at the ESM-level in the Active Visits app.
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.
Tbh, actually, using SWR configuration instead of useSWRImmutable
actually has some advantages (the global mutate()
function cannot invalidate content loaded with either useSWRInfinite()
or useSWRImmutable()
and we've tended to use Immutable in a few inappropriate places).
Should we have a convention where the SWRConfig values are override-able on a per-app basis?
I mean, those decisions are always possible to make, but I'd rather focus on doing so locally where it makes sense to explore whether some kind of app-wide configuration even makes sense (these sort of technical details definitely shouldn't be part of the standard configuration system).
These changes to the global SWR config disable automatic revalidations by default. The idea is to set up a conservative caching strategy that minimizes automatic data revalidations. In practice, it is very unlikely that the data in a chart will change frequently, so it makes sense to limit the number of revalidations to a bare minimum. Note that the SWRConfig component merges the configuration from the parent context. This means that alternative configurations provided further down the line will override the parent values.
36d18dc
to
c990889
Compare
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
These changes to the global SWR config disable automatic revalidations by default. The idea is to set up a conservative caching strategy that minimizes automatic data revalidations. In practice, it is very unlikely that the data in a chart will change frequently, so it makes sense to limit the number of revalidations to a bare minimum.
Note that the SWRConfig component merges the configuration from the parent context. This means that alternative configurations provided further down the line will override the parent values.
One potential benefit of this approach is a quieter network tab in developer tools, making it easier to identify when a request is actually being made, and to spot any unnecessary requests. It also reduces the likelihood of pending network requests slowing down the UI during mutations.
Screenshots
Related Issue
https://openmrs.atlassian.net/browse/O3-4012
Other