Next.js: feature request: renderPage can pass props to App component directly

Created on 4 May 2018  路  4Comments  路  Source: vercel/next.js

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior


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

Expected Behavior


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
    })

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.

All 4 comments

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 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pie6k picture pie6k  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

kenji4569 picture kenji4569  路  3Comments

renatorib picture renatorib  路  3Comments

sospedra picture sospedra  路  3Comments