Skip to content
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

POC: Preloading queries #84

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

POC: Preloading queries #84

wants to merge 5 commits into from

Conversation

rkistner
Copy link
Contributor

An issue with usePowerSyncWatchedQuery is that the initial render gets an empty array. Apart from not being able to distinguish between "loading" and "no results", there's no easy way to load the data before rendering the component.

To illustrate the issue, I added a 400ms delay to queries. Without this delay, you see a very brief flash, but it's difficult to show in a recording.

Without.Preloading.webm

Some routers such as react-router supports "loaders", which can load content before navigating. This is a great place to load the initial query results, to get this:

With.Preloading.webm

The API for this is still a little tricky. The initial results need to be performed in a loader function, while the watching still happens in the component itself. This PR has a POC of a loading method that loads the initial query results, but additionally preserves the query itself for watching later.

Base automatically changed from todolist-demo-vite to main March 11, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant