Material-ui: [example] Should we stop using getInitialProps with next.js?

Created on 14 Jul 2019  路  10Comments  路  Source: mui-org/material-ui

This is more a question than a issue, but I still post it here as I think this could lead to a pull request on the next.js example.

Next.js v9 is out with an automatic prerendering feature. It can only work if we don't use getInitialProps static function, but this seems to be required to render Material-UI server side. Is there a solution about it?

discussion

Most helpful comment

Next.js automatically determines that a page is static (can be prerendered) if it has no has blocking data requirements.

https://nextjs.org/docs#automatic-prerendering

@damien-monni This happens at the page level, not the _document.js level. Our demos should be good:

Capture d鈥檈虂cran 2019-07-15 a虁 13 32 21

@timneutkens I can't find this pages vs _documents.js distinction documented, maybe it's worth adding somewhere.

All 10 comments

Next.js automatically determines that a page is static (can be prerendered) if it has no has blocking data requirements.

https://nextjs.org/docs#automatic-prerendering

@damien-monni This happens at the page level, not the _document.js level. Our demos should be good:

Capture d鈥檈虂cran 2019-07-15 a虁 13 32 21

@timneutkens I can't find this pages vs _documents.js distinction documented, maybe it's worth adding somewhere.

Interesting, I guess it is coming from something else in my app, probably apollo. I'll check it deeper. Thank you!

Cool, I will assume that the problem is outside of our control. Let us know how your investigation is going. It might help someone else in the futur :).

Pretty sure it's because of Apollo indeed.

oliviertassinari

The example provided works well thank you. I am curious if the behavior of _document could be placed in a custom server ? Similar to the generic SSR docs on material ui.

@jmayergit I guess it would be possible?

Probably not a good idea, in general with Next.js 9 we don't recommend people to start with a custom server and it's reserved for very advanced edge cases.

Hey @oliviertassinari @timneutkens just a random fella here that spent almost 1 hour looking how to implement this without using getInitialProps. And now I discover that since it's on _document it doesn't break SSG 馃檲

Do you think we can put this in the material-ui + next.js documentation?

@sospedra I'm not sure how we could have best answered your concern. Any specific diff suggestions?

Sure, I'll just submit a PR ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanflorence picture ryanflorence  路  3Comments

rbozan picture rbozan  路  3Comments

zabojad picture zabojad  路  3Comments

sys13 picture sys13  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments