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: fine grained storage persister #5125

Draft
wants to merge 1 commit into
base: alpha
Choose a base branch
from

Conversation

DamianOsipiuk
Copy link
Contributor

@DamianOsipiuk DamianOsipiuk commented Mar 13, 2023

Ref: #4693

This is a POC of a persister that works for both sync and async storage

Things that are missing from the currently implemented client persister:

  • throttling
    • do we need it when persisting one query at a time?
  • retry
    • TODO
    • needed for out of space issues that were reported previously
  • single key storage
    • do we really need it? you can search in local storage, but may trigger some people OCD
  • persisting paused mutations
    • offline mode?

How to run?

  • cd examples/vue/persister
  • pnpm i
  • pnpm run dev
  • list is persisted to localStorage and pages to idb

Seems to be working pretty well...

Extending useQuery api layer:

What we could do to make it even better is to add a persister to the option list of useQuery.
This will allow to pass in persister without touching queryFn.
Additionally we would be able to add it to the global defaultOptions of QueryClient if we would like to achieve global client persistance with the least amount of code. Without the need to wrap every queryFn with persister.
Two additional benefits would be the ability to get rid of setTimeout to store the state of query (or maybe we can do it now? I'm not sure). And also we would not have to push queryClient to the persister, as it could be passed to the persister along query function context.

@vercel
Copy link

vercel bot commented Mar 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
query ⬜️ Ignored (Inspect) Mar 13, 2023 at 11:18PM (UTC)

@DamianOsipiuk DamianOsipiuk changed the title feat: fine grained storage persister POC: fine grained storage persister Mar 13, 2023
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9ed0d9a:

Sandbox Source
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

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