You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently SWR fires new requests when these happen:
Component state changes and revalidations after mutations
Polling, error retries
Auto revalidations upon focus, reconnect, etc.
1 and 2 are both user-triggered while 1 has a higher priority. And usually for 1 and 2 each SWR hook has its own configuration and hosted component, with its own “update rhythm“.
However, requests in 3 have a lower priority but they’re more like globally triggered. When refocusing, a resource that’s usually updated infrequently will be revaldiated together with a more real-time resource. If you have 100 useSWR hooks rendered with revalidateOnFocus enabled, 100 requests will be fired when focusing on the page. This doesn’t make much sense but just an easy way to implement.
As an improvement, the most straightforward way is to add rate limiting such as a promise queue to auto revalidations (this might be good enough already just like the backoff retry). And further, a priority or heuristic system can be added to have better auto revalidations based on previous data. More research needed here.
That said, all these might be a bit overkill and might make the behavior non-deterministic. But the goal is always to make the end user experience better by requiring no extra work from the developers.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently SWR fires new requests when these happen:
1 and 2 are both user-triggered while 1 has a higher priority. And usually for 1 and 2 each SWR hook has its own configuration and hosted component, with its own “update rhythm“.
However, requests in 3 have a lower priority but they’re more like globally triggered. When refocusing, a resource that’s usually updated infrequently will be revaldiated together with a more real-time resource. If you have 100
useSWR
hooks rendered with revalidateOnFocus enabled, 100 requests will be fired when focusing on the page. This doesn’t make much sense but just an easy way to implement.As an improvement, the most straightforward way is to add rate limiting such as a promise queue to auto revalidations (this might be good enough already just like the backoff retry). And further, a priority or heuristic system can be added to have better auto revalidations based on previous data. More research needed here.
That said, all these might be a bit overkill and might make the behavior non-deterministic. But the goal is always to make the end user experience better by requiring no extra work from the developers.
Beta Was this translation helpful? Give feedback.
All reactions