-
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
NextSSRInMemoryCache
is not exported by @apollo/experimental-nextjs-app-support/ssr
#262
Comments
Actually I am upgrading from 0.8.0 to 0.9.1 it became broken NextSSRApolloClient is also not usable.
I tried to import and the result:
|
Hmm, it seems like you're getting the RSC entry point (where those shouldn't be available and using them was always a bug). Do you still get that error when you mark the file importing it as Are you maybe building for another runtime such as edge? We got reports about that and I'm looking into that soon (just came back from vacation) |
Assuming you are using the Could you please give
a try? |
The same issue occurs when importing registerApolloClient just copy pasted the example from the github readme |
@Giusti you should be getting an error there if you are not importing What environment are you using this in? |
I found the issue is that in version 0.9.0 the usage is changed, some exports is moved to another new package. To fix the issue, simply change the import from: import {
NextSSRApolloClient,
NextSSRInMemoryCache,
SSRMultipartLink,
} from "@apollo/experimental-nextjs-app-support/ssr"; to: import {
ApolloClient,
InMemoryCache,
SSRMultipartLink,
} from '@apollo/client-react-streaming' I also created a PR #269 to update the documents |
Closing this as I found the solution |
@nodegin as I commented in the PR, that's not the intended way of using it. You should continue to use
|
If you are still encountering issues with that usage, we'll need to investigate that. Is there any chance you can provide us with a reproduction of your issue? |
@phryneas I see, I think you can reproduce it by just installing 0.9.1 and navigate to However changing to import from '@apollo/client-react-streaming' did fix for me, at least my app is running normally. I guess the root cause could be some build config error casuing the re-export not working? |
That might be just a TypeScript error there, what your IDE sees and what the bundler sees are two very different things. Are you importing from Depending on if you are in a RSC, SSR or Browser context, that import points to completely different files. I do have an inkling though - you might have imports that accidentally pull Client files into RSC, or RSC files into Client Components. Could you read through #268 and see if that is similar to your situation? |
Especially thinking about your solution - I believe you have an import chain somewhere that pulls the file with your |
@phryneas Hmm, I see that could be the reason. I have a export * from './apolloClient'
export * from './apolloProvider' But that is just for simplifying the import statement, is that a problem? How about if I import from The behavior was working fine before v0.9.0 |
Yes, with 0.9.0 we aligned with how a React Server Component package should be packaged according to the React team. I'm honestly really sorry for these errors, but this is pretty much the experience it is meant to be :( Your barrel exports here look very much like they could be the problem. |
I did ask around for tools that might help with this on Twitter, and https://github.com/pahen/madge was suggested - maybe that helps you identify these imports faster. |
Hm, I've got to confess, my understanding of SSR and its ways in Next.js 13+ are still lacking. But I'm facing the same error, even with a really minimal setup: https://github.com/JonasDoe/debug-apollo-client. There isn't a
This is not just a type error, since - in the real, deployed application -, calling it will result in an error when the |
@JonasDoe There are three things in Next.js
So you'd use
Exactly, your example is a React Server Component trying to import something that should only be used in SSR and Browser. In RSC, you'd just use ApolloClient from Using the wrong import was always a bug in your app, we just enforce it the way the React team intends it to be enforced (with missing imports) since 0.9.0. |
@phryneas Phew, thanks for the detailed explanation! So if I understand correcly, RSC is the "purest" form of a component and has the highest restrictions. It is encapsulated and doesn't need to synchronize with the client. It can reside in In the next step (SSR), in your example you've added SSR and CSR will, in turn, utilize // lib/client.js
import { HttpLink } from "@apollo/client";
import {
NextSSRInMemoryCache,
NextSSRApolloClient,
} from "@apollo/experimental-nextjs-app-support/ssr";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
export const { getClient } = registerApolloClient(() => {
return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache(),
link: new HttpLink({
uri: "https://main--time-pav6zq.apollographos.net/graphql",
}),
});
}); So for some reason, RSC and SSR come together again, and it differs from the repo's Also, if I understand correctly, the
I don't doubt that, but I wasn't experiencing any faulty behavior prior to |
That pretty much sums it up.
Yup.
If you use You can get more context in this RFC or in this conference talk.
🤦 I know you won't believe it, but I already fixed this blog article twice. This just seems to come back. I fixed it again and contacted some people internally to find out why it keeps switching back.
Yes, quoting from the README:
We will soon have a way of "prefetching for SSR/Browser in RSC" though, see #258.
Yeah, it doesn't really "error", but your bundle size might have been increased significantly, at least we had reports of that. Again, I'm sorry for all of that. We will make some adjustments in the next version where we move the That will hopefully make this a lot better. |
Wow, this the RFC is impressive and rather helpful for some more insights, thank you! (Btw. in
So where's the place I'm supposed to fetch initial data that might change later? I'ld rather do some general fetches at server-side for a performance gain. The RSC does fetches at server side, but isn't really supposed to have overlapping queries with the SSR/CSR, as you quote. In the SSR stage, in turn, doing data fetches (via hooks, now) isn't supported and will be skipped. I would expect that the RSC should fetch this data, and I stringify and pass it to the SSR as initial cache. Is this what #258 is there for?
I'm really grateful that you take your time to explain the framework to users! Not only here in comments, but also at so many other places, which is quite some uphill fighting. |
Yup. That, or you just use |
In
node_modules/.pnpm/@apollo+experimental-nextjs-app-support@0.9.1_@apollo+client@3.9.10_next@14.1.4_react@18.2.0/node_modules/@apollo/experimental-nextjs-app-support/dist/ssr/index.ssr.js
NextSSRInMemoryCache is not exported.
I am using version 0.9.1
The text was updated successfully, but these errors were encountered: