Closed aiji42 closed 3 years ago
This library doesn't support SSG. I don't think it makes much sense to use Relay with traditional SSG sites because you miss out on much of what makes Relay so great including the normalized store for mutations, built-in pagination, and seamlessly lazy-loading part of the page. If you're building a SSG site that does fetch data and commit mutations I'd recommend using Next.js as a server-rendered app.
Can you reconsider this? There is a valid use case for some pages, or some parts of pages, to be SSG, and other parts could be SSR or lazily loaded. An example might be a static website (SSG) with an admin view on the same page (lazily loaded) for edits that push changes to the backend and rebuild the SSG side. In that case, the SSG data can be used to hydrate the cache in the editor view.
Basically, if all the preloaded information does not get stale quickly, and is not customized for a page, there are good reasons to prefer an SSG app.
@chrbala It's possible to use Relay in a client-side only fashion there without using this library. The admin page can be wrapped in a RelayEnvironmentProvider
and use useLazyLoadQuery
. There would only be a performance difference when the admin page is the initial navigation.
As far as populating the cache from the SSG data, there are several issues:
Also to note: this library requires modifications to _app.ts
that ensures Relay is loaded on every single page load. This will incur a performance cost on every other non-admin page in your app I would not recommend taking.
Does this also mean ISG is not supported? Unlike SSG, where the content doesn't change, in ISG you want to update the content periodically, sort of like a cached version of SSR. (Previously I used Apollo which worked both for SSR and ISG.) Do you have any pointers on how Relay could be used for ISG, either with or without this library?
@petrbela relay-nextjs uses getInitialProps
internally for data loading so it's not possible to use with ISG. Additionally, Relay is probably not the library you want to use for statically generated pages. Although the API is nice, it's quite heavy on the page and contributes a significant amount to bundle size.
Question
Does it support ssg (getStaticPaths/getStaticProps)? If so, can you please include it in the README or samples?
Thanks to your abstraction of server-side and client-side store sharing and hydration, it will free us from the hassle of configuration. It's a very exciting project.