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

Server-Side Rendering Error with @apollo/client 3.11.0 in NextJS 14.2.5 #11976

Closed
apshenichniy opened this issue Jul 25, 2024 · 4 comments · Fixed by #11980
Closed

Server-Side Rendering Error with @apollo/client 3.11.0 in NextJS 14.2.5 #11976

apshenichniy opened this issue Jul 25, 2024 · 4 comments · Fixed by #11980
Labels

Comments

@apshenichniy
Copy link

apshenichniy commented Jul 25, 2024

Issue Description

I have a NextJS application using apollo/client v3.11.0. the following error occurs during server-side rendering:

Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering. at Object.useSyncExternalStore (/var/task/node_modules/.pnpm/next@14.2.5_@babel+core@7.24.5_@playwright+test@1.45.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:41308)

The snippet below triggered an error:

"use client";

const Component = () => {
....
  useSubscription(query, {
    fetchPolicy: "no-cache",
    onData: ({ data: { data } }) => {
      if (data) {
        setState(data);
      }
    },
  });

...
};

The error seems to be related to the implementation of the useSubscription hook. Specifically, it appears that the third parameter (callback for getServerSnapshot) is not being passed to the useSyncExternalStore hook:
[Link](

const ret = useSyncExternalStore<SubscriptionResult<TData, TVariables>>(
)

Downgrading to @apollo/client version 3.10.8 resolves the issue.

Link to Reproduction

/

Reproduction Steps

No response

@apollo/client version

3.11.0

@jerelmiller
Copy link
Member

Hey @apshenichniy 👋

You're right! We did some refactoring in useSubscription for 3.11 to better work with React Compiler, but looks like we forgot to add that 3rd argument for SSR. useSyncExternalStore was added in 3.11 with this.

I'll dig into this soon and try and figure out what we did before in the SSR case to ensure we mimic that here. Thanks for bringing this to our attention!

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

@jerelmiller
Copy link
Member

Hey @apshenichniy 👋

This was just released in 3.11.2. Please upgrade to that version and you should see the error go away. Thanks for reporting this!

Copy link
Contributor

github-actions bot commented Sep 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants