Bug on NextJS hooks example when using react-apollo-hooks
See original GitHub issueWhen using Material UI hooks with NextJS and react-apollo-hooks, received bug - TypeError: Cannot read property 'theme' of undefined at MyDocument.render (/material-ui/examples/nextjs-hooks-with-typescript/.next/server/static/development/pages/_document.js:156:38)
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
Able to use Material UI hooks and Apollo hooks together.
Current Behavior 😯
undefined
pageContext
caused TypeError: Cannot read property 'theme' of undefined
at line:
https://github.com/ivawzh/material-ui/blob/fc6ae01e66bde4252a08903719a59ef108e05e5f/examples/nextjs-hooks-with-typescript/pages/_document.tsx#L14
Steps to Reproduce 🕹
I have prepared a repo here https://github.com/ivawzh/material-ui/commit/fc6ae01e66bde4252a08903719a59ef108e05e5f
Steps:
git clone git@github.com:ivawzh/material-ui.git
cd material-ui/examples/nextjs-hooks-with-typescript
npm install && npm run dev
- In web browser, open
http://localhost:3000/countries2
- See the error in your terminal
Context 🔦
I am trying to use Apollo hooks with Material UI hooks example.
From the repo above you will see the non-hook Apollo endpoint at http://localhost:3000/countries
is working fine as expected. But when Apollo hooks is in used, app will crash because pageContext
becomes undefined.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.8.1 |
React | 16.7.0-alpha.2 |
Browser | Chrome |
TypeScript | 3.2.2 |
react-apollo | 2.3.3 |
react-apollo-hooks | 0.2.1 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
@ivawzh We are introducing a server-side rendering API: #15030. You can apply the same pattern now:
It fixes the problem on my end.
@ivawzh If you move the server-side queries to get getIntialProps, it’s not great but doable. Google Crawler stats are around 300ms of latency on our website (we index millions of pages). Ideally, we would like to see 100ms, it’s important for websites relying on SEO with a lot a lot a lot of pages. The DX is awesome, I think that it worth the tradeoff. I have nothing public if not the examples we have here.