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

SSR support #3

Merged
merged 7 commits into from
Apr 12, 2023
Merged

SSR support #3

merged 7 commits into from
Apr 12, 2023

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Apr 11, 2023

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 )

Comment on lines 9 to 32
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>
);
}
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 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.

@phryneas
Copy link
Member Author

Let's get this in for now, we can iterate on it.

@phryneas phryneas merged commit 861765c into main Apr 12, 2023
@phryneas phryneas deleted the pr/ssr branch March 6, 2024 10:49
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.

1 participant