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

feat(react): Allow passing a server snapshot to useQuery. #3686

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

Conversation

aboodman
Copy link
Contributor

@aboodman aboodman commented Feb 2, 2025

This enables basic SSR/handoff.

Copy link

vercel bot commented Feb 2, 2025

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

Name Status Preview Comments Updated (UTC)
replicache-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 9:27am
zbugs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 9:27am

@@ -164,6 +183,7 @@ export class ViewStore {
clientID: string,
query: AdvancedQuery<TSchema, TTable, TReturn>,
enabled: boolean,
requireComplete: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

switch to an options object now that we're at 2 boolean args?

);
// https://react.dev/reference/react/useSyncExternalStore
return useSyncExternalStore(
view.subscribeReactInternals,
view.getSnapshot,
view.getSnapshot,
serverSnapshot
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have an example of how someone uses zero on the server to populate this?

Something like this?

const q = z.query.issue.related('assignee');
export async function getServerSideProps() {
  return { issues: await q.run() }
}

function MyComponent({issues}) {
  const q = useQuery(q, {serverSnapshot: issues});
  ...
}

Unclear to me how you hydrate a tree of components with SSR without one giant query at the root.

@aboodman
Copy link
Contributor Author

aboodman commented Feb 3, 2025

Sorry this wasn’t ready for review yet. Put into a draft pr to share early work with @jjenzz

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