conradkohC
Convex Community2y ago
74 replies
conradkoh

Stale while revalidate for re-subscribed queries

Between page navigations, pages mount queries that subscribe or unsubscribe. This results in loaders always triggering on a new subscription when a user navigates.

Proposal: To improve the time to render, serve stale data from a cache (in memory) while the query subscription is still pending, especially if the user was on that page in the same session. In this case, we use non-persistent storage for the objects, so a session is assumed to be until the user refreshes the page.

Here's a proof of concept:
https://github.com/conradkoh/baby-tracker/blob/master/apps/mobile/lib/convex/use_query_swr.tsx#L5-L46

This solution duplicates in memory the objects returned from the server.

If there is first class support for such caching from the library, similar to how react-query does it, but with real time features, it would be amazing.
GitHub
Contribute to conradkoh/baby-tracker development by creating an account on GitHub.
baby-tracker/apps/mobile/lib/convex/use_query_swr.tsx at master · c...
Was this page helpful?