Configuring Material UI with Next.js and react-apollo; correct usage of getDataFromTree

Viewed 238

I have an existing application in which I've encountered a problem. The root of the problem, as far as I know, lies in a broken Apollo query (for example, when trying to spread data whilest it's still undefined). This leads to a wierd UI, in which there are humongous icons and to a warning of such kind:

Warning: Prop className did not match. Server: "MuiSvgIcon-root-69" Client: "MuiSvgIcon-root"

After some research, I found out that the reason of this may be the disableGeneration prop which should be set to true for performance reasons, but I also suspect that if it's turned on then MUI skips the className generation and yields correct classnames as the result.

The question is: what is the correct way to use it, or is there any other way to fix this issue? My stacks is as follows:

  • next.js 9.1.1
  • material UI 4.6.0
  • react-apollo 3.1.2

I have tried several combinations of using StylesProvider and ServerStyleSheets, though I haven't managed to get the job done. Currently I'm using this in _document.js:

const sheets = new ServerStyleSheets({
  injectFirst: true
});

And this is the way I use getDataFromTree, though it looks quite odd to me:

const sheets = new ServerStyleSheets({
  disableGeneration: true
});

await getDataFromTree(sheets.collect(<AppTree {...appProps} />));

I had done a lot of googling but couldn't find a concise result of how to use SSR with Apollo & Material. Any help would be much appreciated :)

0 Answers
Related