-
Notifications
You must be signed in to change notification settings - Fork 450
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
NextJS Server Components and Subscriptions Example #2715
Comments
Hi, There is also some SSR stuff here: https://github.com/nhost/nhost/blob/main/examples/nextjs/pages/public-ssr.tsx Unfortunately, there are too many ways to do different things with Next.js, making it challenging to cover all in a single example. As a result, various things may be illustrated across different examples :( Regards |
The SSR example shows how to set the session using the pages router in nextjs but this approach I don't think is compatible with app router. The server components example using app router does not show how to configure NhostProvider nor NhostApolloProvider. |
I created a repo based off of the nhost server components quickstart project. It is still very buggy but with the issue mentioned in the original post. It does implement SSR data fetch, CSR data fetch, and CSR subscriptions. I had to do some hacking on the NhostSession cookie as the different nhost packages seem to expect different formats. |
Great, this is very cool. I will ask a colleague to take a look. Is there anything in particular you need help with here?
What do you mean? Could you point me to the inconsistencies, please? AFAICT the only valid type for the NhostSession is the one defined here |
The quickstart nextjs-server-components example base64 encodes the session. I wasn't sure what the reason for that was. The @nhost/nextjs and @nhost/react packages seem to set the cookie not base64 encoded.
I am going to continue working on the example project today to better demonstrate the challenges keeping the auth state in sync. |
I also added auth state on the home page. This produces error Logging in and out does not invalidate the cache on the client rendered components. I would have expected the @nhost/nextjs version to properly handle this. |
A colleague will take a deeper look on a best-effort basis but a few comments for now:
|
Your points make sense. Can you explain why this occurs:
|
Is your feature request related to a problem? Please describe.
I have spent hundreds of hours trying to get NextJS server components and client-side subscriptions working together with authorization. Having the session work both on the backend and frontend, keeping the session alive, and keeping the server rendered user state in sync with the client-side state has been a nightmare. There are the black boxes: @nhost/apollo, @nhost/core, @nhost/nextjs, @nhost/nhost-js, @nhost/react-apollo. Keeping them all in sync and knowing which NhostClient from a particular package to use is not always obvious.
Describe the solution you'd like
Update or create a new example using all of the major features of Nhost in a single NextJS with server components project.
Features I would like to see:
The text was updated successfully, but these errors were encountered: