useSWRInfinite has unbounded memory usage #2626
Unanswered
jedwards1211
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
useSWRInfinite
is designed to just keep fetching pages forever without evicting any from the beginning of the list to keep memory usage bounded. This makes in unusable for any cases where the user could conceivably scroll down for a very long time, like a social media app, and cause the page to run out of memory.If something bills itself as "infinite" I'd expect it to at least be able to reach row 2^32 without running out of memory.
This is more of an "infinite memory usage" implementation.
Description / Observed Behavior
I can see from the docs for
useSWRInfinite
that there is no way to evict pages from the beginning of the list and refetch them later.Expected Behavior
I expected it to support limiting the number of pages it will keep in memory. If you set the limit to 100 pages for example, and the user scrolls down to where page 105 is loaded, then it would evict the first 5 pages from memory and keep track of how much of a gap there is at the beginning. Then it would be able to refetch pages at the beginning if the user scrolls back up.
Repro Steps / Code Example
Or share your code snippet or a CodeSandbox link is also appreciated!
Additional Context
SWR version.
Add any other context about the problem here.
Beta Was this translation helpful? Give feedback.
All reactions