-
Notifications
You must be signed in to change notification settings - Fork 43
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
base: main
Are you sure you want to change the base?
Conversation
This enables basic SSR/handoff.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -164,6 +183,7 @@ export class ViewStore { | |||
clientID: string, | |||
query: AdvancedQuery<TSchema, TTable, TReturn>, | |||
enabled: boolean, | |||
requireComplete: boolean, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Sorry this wasn’t ready for review yet. Put into a draft pr to share early work with @jjenzz |
This enables basic SSR/handoff.