-
Notifications
You must be signed in to change notification settings - Fork 36
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
SSR support #3
SSR support #3
Conversation
function makeClient() { | ||
return new ApolloClient({ | ||
cache: new NextSSRInMemoryCache(), | ||
link: new HttpLink({ | ||
uri: "http://localhost:3000/api/graphql", | ||
fetchOptions: { cache: "no-store" }, | ||
}), | ||
}); | ||
} | ||
|
||
function makeSuspenseCache() { | ||
return new SuspenseCache(); | ||
} | ||
|
||
export function Providers({ children }: React.PropsWithChildren) { | ||
return ( | ||
<ApolloProvider | ||
makeClient={makeClient} | ||
makeSuspenseCache={makeSuspenseCache} | ||
> | ||
{children} | ||
</ApolloProvider> | ||
); | ||
} |
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.
This shows a "typical" use in a SSR environment: We have this Provider
file with "use client"
that uses the (for now) "@apollo/experimental-next/dist/ssr"
ApolloProvider
and uses the NextSSRInMemoryCache
.
Then we hook that up in the Layout
and use the hooks from "@apollo/experimental-next/dist/ssr"
in client components.
Let's get this in for now, we can iterate on it. |
This is a first attempt at SSR support.
It irritatingly still errors with hydration problems at the first render after app start, but everything after that is fine. Still have to look into that, something with id generation. It might also just be a next/react bug at this point, though.
Edit: that rehydration bug only occurs in NextJS dev mode on the first execution after start. (I opened an issue: vercel/next.js#48284 )