Skip to content

Add initial Data preparing for SSR support #127

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andr-ec
Copy link

@andr-ec andr-ec commented May 30, 2025

Hey guys I had a stab at implementing initial data as a first step for SSR support. I can do hydration provider etc similar to tanstack query in a separate pull request.

Copy link

changeset-bot bot commented May 30, 2025

⚠️ No Changeset found

Latest commit: 670c9ab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

* Initial data for server-side rendering
* Allows hydration from server-loaded data
*/
initialData?: Array<T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to think about this more but I don't think collections in general will want an initialData option. TanStack Query is around conventions for you directly managing a client cache. TanStack DB aims to be a bit higher-level where these collection types take over managing the cache for you.

So in this world, the QueryCollection might have an initialData option but not necessarily other collections (e.g. Electric wouldn't).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll probably just want an API which awaits running a query (i.e. all the collections are loaded and the query runs). So combination of TanStack/query#9135 & #129

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that makes sense for electric.

If there's an api which awaits running a query, would that just be a similar api to the the react query ssr hydration and rehydration?

https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an api which awaits running a query, would that just be a similar api to the the react query ssr hydration and rehydration?

Yeah exactly. Our general API goal is to copy TanStack Query directly whenever possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like TanStack Query uses initial data as well. still remove initial data?

https://tanstack.com/query/latest/docs/framework/react/guides/ssr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can add it back later if people ask.

@KyleAMathews
Copy link
Collaborator

The refactors are done if you'd like to pick things up again!

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.

2 participants