-
-
Notifications
You must be signed in to change notification settings - Fork 635
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
[Discussion] using Apollo Client's queryPreloader
in TanStack router loaders
#1675
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Things I believe to be true from reading the source code:
Also looking at the changes in the PR:
|
Thanks for the pointers! Reading up on it, I believe I rather need |
I'm not too familiar with how Apollo Client handles hydration/dehydration, but from a quick cursory look at the docs: Server-side: // Add this import to the top of the file
import { getDataFromTree } from "@apollo/client/react/ssr";
// Replace the TODO with this
getDataFromTree(App).then((content) => {
// Extract the entirety of the Apollo Client cache's current state
const initialState = client.extract();
// Add both the page content and the cache state to a top-level component
const html = <Html content={content} state={initialState} />;
// Render the component to static markup and return it
res.status(200);
res.send(`<!doctype html>\n${ReactDOM.renderToStaticMarkup(html)}`);
res.end();
}); Client-side: const client = new ApolloClient({
cache: new InMemoryCache().restore(window.__APOLLO_STATE__),
uri: 'https://example.com/graphql'
}); If this method also dehydrates the client's cache to support streaming as well, you could call Otherwise, could you link to any docs or some source code on how to get hydration via. streaming working with Apollo Client? |
There is no extra hydration beyond what I showed here - hydration would be a side effect of the These old patterns of "dehydrate the full store" and "hydrate the full store" don't work in We have alternative transport mechanisms for the suspenseful |
Please don't merge, this is just a PR because it allows me to easily highlight code changes to the default example :)
We talked about support for Apollo Client's
queryPreloader
in TanStack router loaders yesterday, and I promised you a write-up what we need.Having created this example, I'm not even sure if we need anything more at this point 😅
Generally, we need these things:
loader
function return valuesloader
function values as soon as possibleuseLoaderData
is calledclient
increateRouter
, but it would be even better if the transformer had access to the currentcontext
in some way - this way,router.update
could change the client instance without things breaking.So, this is much less of a feature request than I initially imagined - more of a bunch of questions at this point:
transformer
return objects that containPromise
intances?@defer
, where the response arrives in chunks, so this would be really cool!context
to thetransformer
?transformer
? Could be useful if more libraries start shipping transformers :)Adding @jerelmiller to the discussion, too :)