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: hydration helpers [proof of concept] #877

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

Conversation

juliusmarminge
Copy link
Member

Closes #876


async function PostListWrapped() {
const posts = await api.post.all();
setQueryData((t) => [t.post.all, undefined], posts); // would be cool if this was automatically put to the cache
Copy link
Member Author

Choose a reason for hiding this comment

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

this could be abstracted away by a createCaller equivalent from @trpc/react-query that would automatically set data to a query client cache, then the user would just need to put in <HydrateClient> blocks whereever they need to have live, updated data in client components

</Suspense>
</div>
</div>
</main>
);
}

async function PostListWrapped() {
const posts = await api.post.all();
Copy link

Choose a reason for hiding this comment

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

  1. Maybe the result of api.post.all() could be branded somehow so we know the or can figure out the full query key

Comment on lines 45 to 48
setQueryData((t) => [t.post.all, undefined], posts); // would be cool if this was automatically put to the cache

return (
<HydrateClient>
Copy link

Choose a reason for hiding this comment

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

  1. If it was posts were branded, we could do some helper that automatically knew how to add it in the RQ cache, like
<HydrdateClient queries={[ posts ]}>
   <PostList />
</HydrateClient>

Copy link

Choose a reason for hiding this comment

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

Or maybe it could be something altogether automagic similar to https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr#experimental-streaming-without-prefetching-in-nextjs

and we'd just have a root <Hydrate> thing in the layout that somehow had a stream of data it pushed to the cache (not sure if it's technically feasible unless we can hack RSC<->client comms to work with streams or async iterators

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.

feat: Hydrate Client Component (QueryClient) state w/ dehydrate in RSC
2 participants