next.js 中的 apollo-client with `next-with-apollo` VS next.js docs FAQ 中显示的方法(不使用 `getDataFromTree`)

apollo-client in next.js with `next-with-apollo` VS the approach shown in next.js docs FAQ (no use of `getDataFromTree`)

next-with-apollo npm 库和 the approach shown in next.js docs.

中选择的“next.js 中的 apollo-client”方法的对比

next.js 为 apollo 客户端选择的方法link:https://github.com/vercel/next.js/blob/canary/examples/with-apollo/lib/apolloClient.js

In next.js doc approach:

next-with-apollo 方法中的一些缺点

这让我很好奇看到许多人都在使用 next-with-apollo 而很少看到 approach shown in next.js docs 的用法?我很好奇 next.js 文档中的方法是否有任何缺点(我强烈认为没有任何缺点)?

那么客户端抓取和服务端抓取哪个更好同时支持CSR和SRR?

我通过在 next.js 社区发帖找到了答案:

开始了:

next.js doc's apollo examples avoid using getDataFromTree because it traverses the react tree twice in order to trigger all the queries and collect their result afterwards.

The drawback of using the approach on the next.js doc's apollo examples is since you don't use getDataFromTree, you have no way to know which queries your inner components are using. So you need to remember to prefetch everything you need on getStaticProps/getServerSideProps and match the exact same queries/variables

next.js doc's apollo examples way is recommended instead of getInitialProps so I would always use them unless one has some very specific reason not to