currently material-ui use renderPage to pass pageContext to page Component
// _documents.js
const page = ctx.renderPage(Page => props => (
<Page pageContext={pageContext} {...props} />
));
so, every page components need to handle pageContext
// pages/index.js
export default withRoot(Home) // <-- withRoot HOC handle pageContext
but i really want '_app.js' handle withRoot or other HOC,
so every page components can be more simplier.
currently _document.js can use renderPage to pass props to Page Component such as 'pageContext' above.
its for style ssr.
but _document.js can't send props to App Component``_app.js.
u only can modify App props by custom it /page/_app.js, and then generate App props by getInitialProps function.
https://github.com/zeit/next.js/blob/canary/server/render.js#L79-L88
but, again, _document.js can't send props to _app.js directly if i want to handle something about style ssr in _app.js, so that i don't need write those same code in every pages
may be Next.js would modify the renderPage function, may be add appProps below
const renderPage = (enhancer = Page => Page, appProps) => {
const app = createElement(App, {
Component: enhancer(Component),
router,
...props,
...appProps
})
This is also making it impossible to use styled components ssr when you're using styled components in _app.js. I _think_ one solution that avoids breaking changes could involve some sort of renderApp hook that behaves the same as renderPage, but enhances the _app.js component instead.
There鈥檚 an open PR about where the enhancer in renderPage is used, it should wrap App now, but we鈥檙e still working out potential issues.
鈽濓笍 Is there a link to that PR? I'd like to take a look at it 馃槃
Most helpful comment
There鈥檚 an open PR about where the enhancer in renderPage is used, it should wrap App now, but we鈥檙e still working out potential issues.