next-apollo-ssr
next-apollo-ssr copied to clipboard
ctx.appProps is undefined on first render
Hello! First of all, thank you so much for this extremely complete example of SSR using getDataFromTree
as the recommended route of duplicating queries on SSR involves so much more developer overhead.
I have been following this code as an example in a NextJS 12 Typescript project and noticed that the appProps
passed into the ctx.AppTree
is undefined
on first render, and perhaps not even present on the ctx
object provided to getInitialProps
. I was wondering, is this expected? I cloned this project and verified the same behavior on both NextJS 11 and 12.
console.log
ging the appProps
just above the line where the tree is rendered:
The line I'm following: https://github.com/shshaw/next-apollo-ssr/blob/909ae5922377fe0c759c0c1f37a6b32aa773f301/pages/_document.js#L33
If this isn't expected, do you have any ideas on how to properly construct/retrieve the appProps
required for the app tree? I could always pass in mocked values, but I worry that down the line some queries that depend on static app props may be written, in which case this would cause a failure to hydrate on SSR.
I have the same issue, but still didn't find any weird SSR behaviors. I was able to handle these TS errors by declaring getInitialProps
as such:
static async getInitialProps(
ctx: DocumentContext & { appProps: Record<'pageProps', unknown> },
)