Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example] Should we stop using getInitialProps with next.js? #16598

Closed
damien-monni opened this issue Jul 14, 2019 · 10 comments
Closed

[example] Should we stop using getInitialProps with next.js? #16598

damien-monni opened this issue Jul 14, 2019 · 10 comments

Comments

@damien-monni
Copy link

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?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 15, 2019

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 à 13 32 21

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

@damien-monni
Copy link
Author

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

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 16, 2019

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 :).

@timneutkens
Copy link
Contributor

Pretty sure it's because of Apollo indeed.

@jmayergit
Copy link

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.

@oliviertassinari
Copy link
Member

@jmayergit I guess it would be possible?

@timneutkens
Copy link
Contributor

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.

@sospedra
Copy link
Contributor

sospedra commented Apr 27, 2020

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?

@oliviertassinari oliviertassinari changed the title Next.js example, could we stop using getInitialProps with next.js v9? [example] Should we stop using getInitialProps with next.js? Apr 27, 2020
@oliviertassinari
Copy link
Member

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

@sospedra
Copy link
Contributor

Sure, I'll just submit a PR ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants